fixed adapter

This commit is contained in:
Dan Mihailescu 2024-12-15 12:05:54 -05:00
parent 227fe5ae14
commit cc08ab0e48
2 changed files with 30 additions and 15 deletions

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

@ -19,8 +19,21 @@ model User {
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 {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
title String title String
@ -29,11 +42,3 @@ model Post {
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)
}