mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-28 17:29:36 +02:00
Added auth!
This commit is contained in:
parent
3fd6d021f7
commit
372db59211
18 changed files with 1887 additions and 20 deletions
38
src/lib/server/auth.ts
Normal file
38
src/lib/server/auth.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle";
|
||||
import { Lucia } from "lucia";
|
||||
import { dev } from "$app/environment";
|
||||
import { userTable, sessionTable } from "$lib/db/schema";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { Argon2id } from "oslo/password";
|
||||
|
||||
const adapter = new DrizzlePostgreSQLAdapter(db, sessionTable, userTable);
|
||||
|
||||
export const lucia = new Lucia(adapter, {
|
||||
sessionCookie: {
|
||||
attributes: {
|
||||
secure: !dev,
|
||||
},
|
||||
},
|
||||
getUserAttributes: (attributes) => {
|
||||
return {
|
||||
// attributes has the type of DatabaseUserAttributes
|
||||
username: attributes.username,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
declare module "lucia" {
|
||||
interface Register {
|
||||
Lucia: typeof lucia;
|
||||
DatabaseUserAttributes: DatabaseUserAttributes;
|
||||
}
|
||||
}
|
||||
|
||||
interface DatabaseUserAttributes {
|
||||
username: string;
|
||||
}
|
||||
export interface DatabaseUser {
|
||||
id: string;
|
||||
username: string;
|
||||
hashed_password: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue