Colin
Colin
Explore posts from servers
KKinde
Created by Colin on 2/10/2024 in #💻┃support
Permissions and roles not updating after a change using the Nuxt module
Following https://discord.com/channels/1070212618549219328/1205374262878412810 and https://discord.com/channels/1070212618549219328/1204727161794338849 I'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,
}
}
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?
13 replies
KKinde
Created by Colin on 2/7/2024 in #💻┃support
Best way to access the management API from Nuxt server routes?
Hello, I am kinda new to working with Kinde and am planning on using it for my future projects as it has been a very nice experience till now. I was trying to figure out the best way to access the management API from a Nuxt server route. My current use case is to add a role to a user from a stripe subscription webhook. It is written in the module's docs that the management API is a feature that has not yet seen the day but should still be accessible as it uses the Typescript SDK under the hood right? Here is the project I am working on: https://github.com/ColinEspinas/starter Have a wonderful day, Colin.
42 replies
DTDrizzle Team
Created by Colin on 7/24/2023 in #help
Placeholder in updates
Hello, I just started using drizzle by doing a very simple todo app. I have some trouble understanding how to get dynamic values inside the object taken by the set function on update. Here is my non-working code:
const prepared = db.update(tasks)
.set({ state: placeholder('state') })
.where(eq(tasks.id, placeholder('id')))
.prepare('update-task')
const prepared = db.update(tasks)
.set({ state: placeholder('state') })
.where(eq(tasks.id, placeholder('id')))
.prepare('update-task')
The second placeholder (id) seems to work great but I can't figure anyway to make the state dynamic here in a prepared query. Maybe using a "raw sql" string would just work but this use case seems to frequent to just default to this. Have a great day, Colin.
2 replies