Problem with google provider and next-auth.
Im having difficulties figuring out how to fix this error:
nique constraint failed on the constraint:
users_username_key
{
message: '\n' +
'Invalid prisma.user.create()
invocation:\n' +
'\n' +
'\n' +
'Unique constraint failed on the constraint: users_username_key
',
stack: 'PrismaClientKnownRequestError: \n' +
'Invalid prisma.user.create()
invocation:\n' +
'\n' +
'\n' +
'Unique constraint failed on the constraint: users_username_key
\n' +
' at si.handleRequestError (D:\prgrammeringsprojekt\next-ecommerce-project\project\node_modules\@prisma\client\runtime\library.js:125:6817)\n' +
' at si.handleAndLogRequestError (D:\prgrammeringsprojekt\next-ecommerce-project\project\node_modules\@prisma\client\runtime\library.js:125:6151)\n' +
' at si.request (D:\prgrammeringsprojekt\next-ecommerce-project\project\node_modules\@prisma\client\runtime\library.js:125:5859)\n' +
' at async l (D:\prgrammeringsprojekt\next-ecommerce-project\project\node_modules\@prisma\client\runtime\library.js:130:10025)',
name: 'PrismaClientKnownRequestError'
}
I have a next.js application that is is running on my local machine and im trying to log in with different gmail accounts but when I log in with 1 I cant log in with any other gmail account afterwards that Ive added as test-users in the google console and connected to my next.js application.
I'm using prisma with mongodb.
anyone familiar with error?6 Replies
Unique constraint failed on the constraint: users_username_key
This means that you're trying to insert something into a database that doesn't allow duplicates on a certain column, likely the users.username
column in this caseHi and ty for the quick reply. That I am aware of, but I'm quite unsure about how to handle this. since this is handled by the google provider I thought it'd be handled automatically. I have schemas set up accordingly to the docs. model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
email String? @unique
username String? @unique
password String?
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Cart Cart[]
Review Review[]
Order Order[]
@@map("users")
}
I'm not particularly familiar with any of the tools you're using. Did you write that schema?
Ive only added Review , Order and Cart, other than that these things comes from the docs.
my first guess would be that you're using a test string somewhere and feeding it in as the username, and it's failing on the second because the test string isn't updated.
hard to tell without the rest of the code though (and like I said, I'm not particularly familiar with any of it, but someone else might be)
I hope so 🙂 thanks for replying though. Appreciated.