I’m using an example vue’js project:
I don’t seem to be able to retrieve user profile information following a login. I have tried adding the block that calls client.userInfo() in the login code as below:
handleAuthentication () {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult)
this.auth0.client.userInfo(authResult.accessToken, function (err, user) {
localStorage.setItem('user_details', user)
console.log(user)
console.log(err)
})
router.replace('home')
} else if (err) {
router.replace('home')
console.log(err)
alert(`Error: ${err.error}. Check the console for further details.`)
}
})
}
But my user object doesn’t appear to hold any data. Can anyone spot what I’m missing here?
UPDATE
Here is access to the HAR file:
To clarify, what I’m doing (from the VueJS example Auth0 provides) I’m:
-
making a client.userinfo request inside the parseHash method:
this.auth0.client.userInfo(authResult.accessToken, function (err, user) {
localStorage.setItem(‘user_details’, user)
… -
providing a method to retrieve this in the AuthService:
getUser(){
return JSON.stringify(localStorage.getItem(‘user_details’))
} -
Providing the the AuthService as a prop to my home component from my app.vue:
const auth = new AuthService()
-
Receiving this in the home.vue component and calling getUser() to show the user details:
{{ auth.getUser() }}
There isn’t a problem accessing the authService prop in my home.vue component as I have code that runs the logout function from here in much the same way:
<h4 v-if="authenticated">
You are logged in!!
<a @click="auth.logout()">Log Out</a>
</h4>
This project is based on the VueJS example project Auth0 provides so am unsure what I could be doing wrong. All documentation I have found seems to confirm that calling this.auth0.client.userInfo(authResult.accessToken, function(err, user) {… should result in the user object being populated as per the example json data shown on the success page when you click the ‘try it’ button from the Auth0 dashboard.