Lucia Authentication #8

Merged
DanMihailescu merged 18 commits from undoPretty into master 2024-12-19 20:06:45 -05:00
2 changed files with 30 additions and 15 deletions
Showing only changes of commit cc08ab0e48 - Show all commits

View file

@ -1,12 +1,22 @@
import { Lucia } from "lucia"; import { Lucia } from "lucia";
//import { dev } from "$app/env";
import { PrismaAdapter } from "@lucia-auth/adapter-prisma"; import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
import { PrismaClient } from "@prisma/client"; import { PrismaClient } from "@prisma/client";
const client = new PrismaClient(); const client = new PrismaClient();
const adapter = new PrismaAdapter(client.session, client.user) const adapter = new PrismaAdapter(client.session, client.user)
// expect error (see next section) // expect error (see next section)
export const auth = new Lucia({ export const auth = new Lucia(adapter, {
sessionCookie: {
attributes: {
// secure: !dev
}
},
getUserAttributes: (attributes)=>{
return {
email: attributes.email
}
}
}); });
export type Auth = typeof auth; export type Auth = typeof auth;

View file

@ -15,12 +15,25 @@ datasource db {
} }
model User { model User {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
email String @unique email String @unique
name String? name String?
posts Post[] posts Post[]
sessions Session[]
} }
model Session {
id String @id @default(cuid())
expiresAt DateTime
sessionToken String @unique
accessToken String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId Int
user User @relation(references: [id], fields: [userId])
}
model Post { model Post {
BenjaminPalko commented 2024-12-17 14:10:51 -05:00 (Migrated from github.com)
Review

NIT: references and fields is backwards from how post shows it, can we keep them consistent

NIT: references and fields is backwards from how post shows it, can we keep them consistent
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
title String title String
@ -28,12 +41,4 @@ model Post {
published Boolean @default(false) published Boolean @default(false)
author User @relation(fields: [authorId], references: [id]) author User @relation(fields: [authorId], references: [id])
authorId Int authorId Int
} }
model Session {
id String @id
userId String
expiresAt DateTime
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
}