Double Lucia Instances: Admin and Customer Management #951
-
Is it possible to use two separate instances of Lucia, one for admin users and another for customers? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
If my initial question was unclear, can i define const customerAuth = lucia({ /* options */});
const adminAuth = lucia({/* options */}); and then use them independently? |
Beta Was this translation helpful? Give feedback.
-
Sorry for the late response. Currently you can't have multiple lucia() instances or else types for User and Session will break. |
Beta Was this translation helpful? Give feedback.
-
I was able to do this by modifying the Lucia User interface in - export interface User extends UserAttributes {
- id: UserId;
- }
+ export type User = UserAttributes & {
+ id: UserId;
+ } const customerAuth = new Lucia(customerDbAdapter, { ... });
const adminAuth = new Lucia(adminDbAdapter, { ... });
declare module 'lucia' {
interface Register {
Lucia: typeof customerAuth | typeof adminAuth
DatabaseUserAttributes: Customer | Admin
}
} Not a perfect solution but it works for me. Common props are then accessible on the user object returned from e.g. const { user, session } = await luciaPatient.validateSession(sessionId)
user.id
user.email
user.billingAddress // TypeError
if ('billingAddress' in user) {
// only customers have billingAddress
user.billingAddress // string
} |
Beta Was this translation helpful? Give feedback.
Sorry for the late response. Currently you can't have multiple lucia() instances or else types for User and Session will break.