P
Prisma4d ago
Comfy

Trying to setup better auth

Following this guide https://www.prisma.io/docs/guides/betterauth-nextjs and using the following schema (generated):
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
name String
email String
emailVerified Boolean @default(false)
image String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
sessions Session[]
accounts Account[]

@@unique([email])
@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

expires DateTime @map("expiresAt")
sessionToken String @map("token")

@@unique([token])
@@map("session")
@@unique([sessionToken])
}

model Account {
id String @id
type String?
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

providerAccountId String @map("accountId")
access_token String? @map("accessToken")
refresh_token String? @map("refreshToken")
id_token String? @map("idToken")
access_token_expires DateTime? @map("accessTokenExpiresAt")

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt

@@map("verification")
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
name String
email String
emailVerified Boolean @default(false)
image String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
sessions Session[]
accounts Account[]

@@unique([email])
@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

expires DateTime @map("expiresAt")
sessionToken String @map("token")

@@unique([token])
@@map("session")
@@unique([sessionToken])
}

model Account {
id String @id
type String?
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

providerAccountId String @map("accountId")
access_token String? @map("accessToken")
refresh_token String? @map("refreshToken")
id_token String? @map("idToken")
access_token_expires DateTime? @map("accessTokenExpiresAt")

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt

@@map("verification")
}
I get:
Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Field "expires" is already defined on model "Session".
--> prisma\schema.prisma:37
|
36 |
37 | expires DateTime @map("expiresAt")
38 | sessionToken String @map("token")
|
error: Field "sessionToken" is already defined on model "Session".
--> prisma\schema.prisma:38
|
37 | expires DateTime @map("expiresAt")
38 | sessionToken String @map("token")
39 |
|
error: Field "providerAccountId" is already defined on model "Account".
--> prisma\schema.prisma:62
|
61 |
62 | providerAccountId String @map("accountId")
63 | access_token String? @map("accessToken")
|
error: Field "access_token" is already defined on model "Account".
--> prisma\schema.prisma:63
|
62 | providerAccountId String @map("accountId")
63 | access_token String? @map("accessToken")
64 | refresh_token String? @map("refreshToken")
|
error: Field "refresh_token" is already defined on model "Account".
--> prisma\schema.prisma:64
|
63 | access_token String? @map("accessToken")
64 | refresh_token String? @map("refreshToken")
65 | id_token String? @map("idToken")
|
error: Field "id_token" is already defined on model "Account".
--> prisma\schema.prisma:65
|
64 | refresh_token String? @map("refreshToken")
65 | id_token String? @map("idToken")
66 | access_token_expires DateTime? @map("accessTokenExpiresAt")
error: Field "access_token_expires" is already defined on model "Account".
--> prisma\schema.prisma:66
|
65 | id_token String? @map("idToken")
66 | access_token_expires DateTime? @map("accessTokenExpiresAt")

Prisma CLI Version : 6.16.2
Error: Prisma schema validation - (get-dmmf wasm)
Error code: P1012
error: Field "expires" is already defined on model "Session".
--> prisma\schema.prisma:37
|
36 |
37 | expires DateTime @map("expiresAt")
38 | sessionToken String @map("token")
|
error: Field "sessionToken" is already defined on model "Session".
--> prisma\schema.prisma:38
|
37 | expires DateTime @map("expiresAt")
38 | sessionToken String @map("token")
39 |
|
error: Field "providerAccountId" is already defined on model "Account".
--> prisma\schema.prisma:62
|
61 |
62 | providerAccountId String @map("accountId")
63 | access_token String? @map("accessToken")
|
error: Field "access_token" is already defined on model "Account".
--> prisma\schema.prisma:63
|
62 | providerAccountId String @map("accountId")
63 | access_token String? @map("accessToken")
64 | refresh_token String? @map("refreshToken")
|
error: Field "refresh_token" is already defined on model "Account".
--> prisma\schema.prisma:64
|
63 | access_token String? @map("accessToken")
64 | refresh_token String? @map("refreshToken")
65 | id_token String? @map("idToken")
|
error: Field "id_token" is already defined on model "Account".
--> prisma\schema.prisma:65
|
64 | refresh_token String? @map("refreshToken")
65 | id_token String? @map("idToken")
66 | access_token_expires DateTime? @map("accessTokenExpiresAt")
error: Field "access_token_expires" is already defined on model "Account".
--> prisma\schema.prisma:66
|
65 | id_token String? @map("idToken")
66 | access_token_expires DateTime? @map("accessTokenExpiresAt")

Prisma CLI Version : 6.16.2
How to use Prisma ORM and Prisma Postgres with Better-Auth and Next...
Learn how to use Prisma ORM in a Next.js app with Better-Auth
5 Replies
Prisma AI Help
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Gregersen
Gregersen4d ago
You could likely easily debug this with AI. You are creating a field expires then mapping it to expiresAt which means the name of the field will be expiresAt, which already exists. Same with token and sessionToken. The errors are right there, telling you what you're doing wrong. You could easily figure this out with AI, reading the manual, or just reading the error messages. I'd recommend removing all/most of the @map on properties, and simply naming your properties what you would like instead, this way is recipe for disaster
Comfy
ComfyOP4d ago
I tried that then better auth didn't work so I just gave up and used clerk it feels like a better-auth issue, but the prisma docs didn't work either
Gregersen
Gregersen4d ago
I see. Yeah the Prisma docs can occasionally feel outdated, I've certainly experienced that a few times. I have personally not had any issues with BetterAuth and have implemented it succesfully in a few apps, and I don't recall anything around the database schema being an issue Sorry I can't be of more specific help for the time being
Comfy
ComfyOP4d ago
No worries, I was also baffled, since I've done the setup quite a few times but this time it just didn't work

Did you find this page helpful?