fosrl.pangolin/server/auth/index.ts

61 lines
1.6 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";
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
};
},
// getSessionAttributes: (attributes) => {
// return {
// country: attributes.country,
// };
// },
sessionCookie: {
name: "session",
expires: false,
2024-10-01 20:48:03 -04:00
attributes: {
2024-10-06 22:09:30 -04:00
// secure: environment.ENVIRONMENT === "prod",
// sameSite: "strict",
secure: false,
2024-10-07 23:31:23 -04:00
domain: ".testing123.io",
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;
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;
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
}
interface DatabaseSessionAttributes {
// country: string;
}