mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-15 08:25:01 +02:00
started integrating auth with lucia
This commit is contained in:
parent
a33a8d7367
commit
fc5dca136f
20 changed files with 1341 additions and 61 deletions
50
server/auth/index.ts
Normal file
50
server/auth/index.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
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 {
|
||||
username: attributes.username,
|
||||
};
|
||||
},
|
||||
// getSessionAttributes: (attributes) => {
|
||||
// return {
|
||||
// country: attributes.country,
|
||||
// };
|
||||
// },
|
||||
sessionCookie: {
|
||||
name: "session",
|
||||
expires: false, // session cookies have very long lifespan (2 years)
|
||||
attributes: {
|
||||
secure: environment.ENVIRONMENT === "prod",
|
||||
sameSite: "strict",
|
||||
// domain: "example.com"
|
||||
},
|
||||
},
|
||||
sessionExpiresIn: new TimeSpan(2, "w"),
|
||||
});
|
||||
|
||||
export default lucia;
|
||||
|
||||
// IMPORTANT!
|
||||
declare module "lucia" {
|
||||
interface Register {
|
||||
Lucia: typeof lucia;
|
||||
DatabaseUserAttributes: DatabaseUserAttributes;
|
||||
DatabaseSessionAttributes: DatabaseSessionAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
interface DatabaseUserAttributes {
|
||||
username: string;
|
||||
passwordHash: string;
|
||||
}
|
||||
|
||||
interface DatabaseSessionAttributes {
|
||||
// country: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue