Getting user role from auth0-vue

Hi all, i am using “@auth0/auth0-vue”: “^1.0.1”, and I am looking for a good way to get get the user roles. In my vue2 project I used the auth0-spa-js and I added this function to a wrapper

isUserRole (role) {
const user = this.$auth.user
const roles = user ? user[‘http://domain.com/roles’] :
if (user && roles) {
return role === roles[0]
}
return false
}

then I would call it like this as a computed property

    isAdmin() {
      return this.$auth.isUserRole("Admin");
    },

Is there a similar way to do this with the new auth0-vue sdk?

Hi there @roman2 welcome to the community!

I am not aware of a way to accomplish this via the SDK, but typically we recommend that roles are added to and read from the user’s ID/Access Token instead - Some more on adding roles as custom claims in tokens here:

Hope this helps!

Hi, thanks I will just read the roles from the users token.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.