2024-10-02 20:42:50 -04:00
|
|
|
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 {
|
2024-10-02 00:04:40 -04:00
|
|
|
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-01 20:48:03 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
// getSessionAttributes: (attributes) => {
|
|
|
|
// return {
|
|
|
|
// country: attributes.country,
|
|
|
|
// };
|
|
|
|
// },
|
|
|
|
sessionCookie: {
|
|
|
|
name: "session",
|
2024-10-02 00:04:40 -04:00
|
|
|
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 {
|
2024-10-02 00:04:40 -04:00
|
|
|
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-04 23:14:40 -04:00
|
|
|
emailVerified: boolean;
|
2024-10-01 20:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface DatabaseSessionAttributes {
|
|
|
|
// country: string;
|
|
|
|
}
|