Next-Auth: Try signing in with a different account.

So this error I am getting in the browser
Try signing in with a different account.
Try signing in with a different account.
This is very common. It usually doesn't tell me what's wrong. The first thing I do when I see this is check my environment variables. Checking if theyre correct. Which they are. I am using create-t3-app So it also checks that for me by default. I am added a Google Provider and when I click on sign in with google, It doesn't redirect me to the correct page. It instead brings me to the /api/auth/signin page with an error message. This is also happening, it redirects me to api/auth/signin?error=OAuthAccountNotLinked And I see this error
To confirm your identity, sign in with the same account you used originally.
To confirm your identity, sign in with the same account you used originally.
Any idea what's going on?
5 Replies
kenny
kennyOP2y ago
I also have a feeling it has something todo with the prisma schemas, so here are the schemas used by Next-auth:
// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
chats Chat[]
messages Message[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime

@@unique([identifier, token])
}
// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
chats Chat[]
messages Message[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime

@@unique([identifier, token])
}
I dropped all the tables in the planetscale console and tried it again, I tried sigining in with google first, which got me this error
To confirm your identity, sign in with the same account you used originally.
To confirm your identity, sign in with the same account you used originally.
Then with Linkedin, same error. Then I tried it with Discord and I got succesfully signed in.
cdi.dev
cdi.dev2y ago
That's probably because you are trying to access it through different social accounts that share the same email. If you've made an account, let's say, with Linkedin and then with Google, and both of them share the same email, nextauth will throw an error. You can check https://next-auth.js.org/faq#security for reference. - The "When I sign in with another account with the same email address, why are accounts not linked automatically?" question in particular
kenny
kennyOP2y ago
Oh i forgot to mention I've tried it with another google account I have tried with another discord account with a different email
cdi.dev
cdi.dev2y ago
From my knowledge, the only time you can get api/auth/signin?error=OAuthAccountNotLinked is "If the email on the account is already linked, but not with this OAuth account". The OAuthAccountNotLinked error is also documented in the https://next-auth.js.org/configuration/pages#sign-in-page
Pages | NextAuth.js
NextAuth.js automatically creates simple, unbranded authentication pages for handling Sign in, Sign out, Email Verification and displaying error messages.
cje
cje2y ago
look at the error in your terminal, theres a link to a next auth documentation page
Want results from more Discord servers?
Add your server