Lucia Authentication #8
2 changed files with 30 additions and 15 deletions
14
lucia.ts
14
lucia.ts
|
|
@ -1,12 +1,22 @@
|
|||
import { Lucia } from "lucia";
|
||||
//import { dev } from "$app/env";
|
||||
import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const client = new PrismaClient();
|
||||
const adapter = new PrismaAdapter(client.session, client.user)
|
||||
// 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;
|
||||
|
|
@ -15,12 +15,25 @@ datasource db {
|
|||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
posts Post[]
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
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 {
|
||||
|
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
|
|
@ -29,11 +42,3 @@ model Post {
|
|||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId Int
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id
|
||||
userId String
|
||||
expiresAt DateTime
|
||||
|
||||
user User @relation(references: [id], fields: [userId], onDelete: Cascade)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue
NIT: references and fields is backwards from how post shows it, can we keep them consistent