fosrl.pangolin/server/auth/index.ts

56 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";
2024-10-12 18:21:31 -04:00
import config from "@server/config";
2024-10-01 20:48:03 -04:00
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-04 23:14:40 -04:00
emailVerified: attributes.emailVerified,
2024-10-07 23:31:23 -04:00
dateCreated: attributes.dateCreated,
2024-10-01 20:48:03 -04:00
};
},
sessionCookie: {
name: "session",
expires: false,
2024-10-01 20:48:03 -04:00
attributes: {
2024-10-12 18:21:31 -04:00
sameSite: "strict",
secure: config.app.secure_cookies || false,
domain:
"." +
config.app.external_base_url
.split("://")[1]
.split(":")[0]
.split("/")[0],
2024-10-01 20:48:03 -04:00
},
},
sessionExpiresIn: new TimeSpan(2, "w"),
});
export default lucia;
declare module "lucia" {
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}
interface DatabaseUserAttributes {
email: string;
2024-10-01 20:48:03 -04:00
passwordHash: string;
2024-10-02 20:19:48 -04:00
twoFactorEnabled: boolean;
2024-10-05 15:31:28 -04:00
twoFactorSecret?: string;
2024-10-04 23:14:40 -04:00
emailVerified: boolean;
2024-10-07 23:31:23 -04:00
dateCreated: string;
2024-10-01 20:48:03 -04:00
}