Replies: 1 comment
-
Of course I can "manually" add them to the object but it requires an additional call to the DB and makes the downstream code uglier because I always have to async function getUserPermissions(userId) {
const user = await prisma.user.findFirst({
where: { id: userId },
include: { permissions: true }
});
if (!user) return [];
return user.permissions.map((permission) => permission.name);
}
export const lucia = new Lucia(adapter, {
sessionCookie: {
attributes: {
secure: !dev // set to `true` when using HTTPS
}
},
getUserAttributes: (attributes) => {
return {
// attributes has the type of DatabaseUserAttributes
email: attributes.email,
name: attributes.name,
permissions: getUserPermissions(attributes.id)
};
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using lucia with prisma in SvelteKit and my users can have permissions attached to them like so:
I would like to include these permissions in the UserAttributes so I can easily access them through the session and not load them from the DB again and again. But just naively including them in the getUserAttributes hook does not seem to work, it simply becomes
undefined
Is there a way to do this? (I'm on lucia v3.2.0 currently).
Beta Was this translation helpful? Give feedback.
All reactions