daphnis/lib/lucia.ts

38 lines
961 B
TypeScript
Raw Normal View History

2024-06-29 05:22:22 +00:00
import { Lucia } from "lucia";
import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
2024-06-29 06:37:50 +00:00
import { daphnis } from "./prisma";
2024-06-29 05:22:22 +00:00
2024-06-29 06:37:50 +00:00
const adapter = new PrismaAdapter(daphnis.session, daphnis.user);
2024-06-29 05:22:22 +00:00
export const lucia = new Lucia(adapter, {
sessionCookie: {
expires: false, // Next.js doesn't allow Lucia to extend cookie expiration when rendering pages
attributes: {
// set to `true` when using HTTPS
secure: process.env.NODE_ENV === "production",
},
},
getUserAttributes: (attributes) => {
return {
// attributes has the type of DatabaseUserAttributes
role: attributes.role,
username: attributes.username,
accessCode: attributes.accessCode,
};
},
});
declare module "lucia" {
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}
// add from userdb
interface DatabaseUserAttributes {
role: string;
username: string;
accessCode: string;
}