fosrl.pangolin/server/auth/index.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

export * from "./unauthorizedResponse";
export * from "./verifySession";
2024-10-01 20:48:03 -04:00
import { Lucia, TimeSpan } from "lucia";
import { DrizzleSQLiteAdapter } from "@lucia-auth/adapter-drizzle";
import db from "@server/db";
import { sessions, users } from "@server/db/schema";
import environment from "@server/environment";
const adapter = new DrizzleSQLiteAdapter(db, sessions, users);
export const lucia = new Lucia(adapter, {
getUserAttributes: (attributes) => {
return {
email: attributes.email,
2024-10-02 20:19:48 -04:00
twoFactorEnabled: attributes.twoFactorEnabled,
twoFactorSecret: attributes.twoFactorSecret,
2024-10-01 20:48:03 -04:00
};
},
// getSessionAttributes: (attributes) => {
// return {
// country: attributes.country,
// };
// },
sessionCookie: {
name: "session",
expires: false,
2024-10-01 20:48:03 -04:00
attributes: {
secure: environment.ENVIRONMENT === "prod",
sameSite: "strict",
// domain: "example.com"
},
},
sessionExpiresIn: new TimeSpan(2, "w"),
});
export default lucia;
declare module "lucia" {
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
DatabaseSessionAttributes: DatabaseSessionAttributes;
}
}
interface DatabaseUserAttributes {
email: string;
2024-10-01 20:48:03 -04:00
passwordHash: string;
2024-10-02 20:19:48 -04:00
twoFactorEnabled: boolean;
twoFactorSecret: string | null;
2024-10-01 20:48:03 -04:00
}
interface DatabaseSessionAttributes {
// country: string;
}