Christoffer
08/14/2022, 8:10 PMmodel AuthProvider {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
type AuthProviderType
externalUserId String? @unique
email String @unique // this should not be unique if the userId is the same among two AuthProviders
emailVerified Boolean? @default(false)
password String? // Hashed password
user User @relation(fields: [userId], references: [id])
userId String
@@map("auth_providers")
}
A user can have many authentication providers, such as email + password, google, twitter... that they can use to sign in with
Now here comes the tricky part:
what I want to accomplish is to make it so an AuthProviders email is unique, but ONLY if the userId of that AuthProvider is different.
So a user should be able to have several AuthProviders with the same email, but if one user tries to connect an authprovider with an email that another user already has connected (on any of their authproviders), then it should fail via unique constraint.
would this be achieveable just using uniuqe constraints/indexes in the schema?Nurul
08/16/2022, 11:39 AMexternalUserId
and email
as unique?Vladi Stevanovic