Following
https://discord.com/channels/1070212618549219328/1205374262878412810 and
https://discord.com/channels/1070212618549219328/1204727161794338849I've been having a hard time getting up to date data from the nuxt module when using the same methods as in the docs.
Here is a composition I've got to handle those operations:
export async function useUser() {
const { user } = useAuth()
const client = useKindeClient()
const { data: permissions } = await useAsyncData(`permissions-${user?.id ?? 'guest'}`, async () => {
const { permissions } = (await client?.getPermissions()) ?? {}
return permissions as string[]
})
const getHasPermission = (permission: string) => {
return permissions.value?.includes(permission) ?? false
}
const { data: roles, refresh: refreshRoles } = await useAsyncData(`roles-${user?.id ?? 'guest'}`, async () => {
const { value } = (await client?.getClaim('roles')) ?? {}
return value as { id: string, key: string, name: string }[]
})
const getHasRole = (role: string) => {
return roles.value?.some(r => r.key === role) ?? false
}
const { data: organization } = await useAsyncData(`organization-${user?.id ?? 'guest'}`, async () => {
const { orgCode } = (await client?.getOrganization()) ?? {}
return orgCode as string
})
return {
permissions,
roles,
organization,
getHasPermission,
getHasRole,
refreshRoles,
}
}
At first I thought it was something to do with the tokens not being refreshed after the update but that does not make much sense as the data for permissions should not be in the token right?
Anyway, I've not had any success in updating the user data. Am I doing something wrong or missing a piece?