vue-auth3
vue-auth3 copied to clipboard
parseUserData Support
Coming from @websanova/vue-auth
, I was wondering if there is an equivalent configuration of parseUserData
to allow me to extract/parse the user data from within my API response, for example when my response looks something like this:
{
"status": "success",
"data": {
"username": "admin",
"role": "admin"
}
}
And the meaningful user data is only
{
"username": "admin",
"role": "admin"
}
I searched the docs and source code and couldn't find an alternative approach.
Your organization has reached the subscribed usage limit. You can upgrade your account by purchasing a subscription at Stripe payment link
You have use keyUser
. This option is available for all child options like login
, refreshData
....
const auth = createAuth({
rolesKey: "type",
notFoundRedirect: "/",
fetchData: {
enabled: true,
cache: true,
keyUser: "data"
},
refreshToken: {
enabled: false,
},
plugins: {
router,
},
drivers: {
http: {
request: app.config.globalProperties.$api,
},
auth: driverAuthBearer,
},
})
Thank you! I got it working as intended.
When checking the docs, I was wondering what the keyUser
option is for, since the description for it and the userKey
options are missing.
After reading the source code and testing, I understood that the userKey
defines the name for the cookie or storage entry of the cached user data.
Also, I'm not sure if this still applies to this thread, but I have another instance where the user contains a boolean "is_admin" field instead of a role
field. I tried to set the rolesKey
to "is_admin" and use $auth.check(true)
to check for admin access, unfortunately without success. A workaround would be to append the role: "admin"
to the user object when fetching the user details, but I didn't find a way of doing it.
try setting the return from your api to include roles: ['admin']
then call .check('admin')
Thank you for your time. I would like to keep the api unchanged, to ensure compatibility between clients (old and new).
In @websanova/vue-auth
there was a parseUserData
configuration function that would allow changing the user object when fetching the user.
Just to be sure, there is no way to change the user object right after the fetch, to append the roles: ['admin']
is case of is_admin: true
, is there?