Flurrih
Flurrih
PPrisma
Created by Flurrih on 8/6/2024 in #help-and-questions
[Prisma][MongoDB][Lucia] Malformed objectID
But I did some debuging around, and for me it looks like Prisma, but its my first time doing those stuff so not sure
6 replies
PPrisma
Created by Flurrih on 8/6/2024 in #help-and-questions
[Prisma][MongoDB][Lucia] Malformed objectID
but then, Im using Lucia:
const session = await lucia.createSession(existingGoogleUser.id, {});
const session = await lucia.createSession(existingGoogleUser.id, {});
So Im not sure if its Prisma's id or Lucia's tbh
6 replies
PPrisma
Created by Flurrih on 8/6/2024 in #help-and-questions
[Prisma][MongoDB][Lucia] Malformed objectID
it seems like the schema is generating it:
id String @id @default(auto()) @map("_id") @db.ObjectId
id String @id @default(auto()) @map("_id") @db.ObjectId
with
@default(auto())
@default(auto())
, but then it expects
@db.ObjectId
@db.ObjectId
and it throws the error. I fixed the issue by doing this:
model Session {
id String @id @default(uuid()) @map("_id")
userId String
expiresAt DateTime

user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(uuid()) @map("_id")
googleId String @unique
name String?
email String @unique
sessions Session[]
}
model Session {
id String @id @default(uuid()) @map("_id")
userId String
expiresAt DateTime

user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(uuid()) @map("_id")
googleId String @unique
name String?
email String @unique
sessions Session[]
}
so Im using uuid() and String - not native MongoDB ObjectID, and it works... Perhaps maybe theres some bug with Prisma somewhere for MongoDB? The User that had the ObjectID was correctly created, but the Session is failing on the ObjectIDs - might be due to userId being reference to ObjectId and have two IDs in one schema?
6 replies