I've seem similar problems and tried some suggestions, even deleted my whole database and created it again, but nothing seems to work.
So Im trying to log in into my application via the Google Provider in Next Auth using the Prisma Adapter and Planet Scale, but somehow I always get this message: "Try signing in with a different account."
This is my schema.prisma:
//As provided by Planet Scale:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
But this is the User model with some custom keys:
// 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)
@@unique([provider, providerAccountId])
@@index([userId])
}
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[]
//this is custom:
userPreference UserPreference?
role String? @default("client")
Timeline TimelineEntry[]
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
And this is [...nextauth].ts:
import NextAuth, { type NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
// Prisma adapter for NextAuth, optional and can be removed
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { env } from "../../../env/server.mjs";
import { prisma } from "../../../server/db";
export const authOptions: NextAuthOptions = {
// Include user.id on session
callbacks: {
async jwt({ token, user }) {
if (user?.role) {
token.role = user.role;
}
return token;
},
async session({ session, user }) {
if (session.user) {
session.user.id = user.id;
session.user.role = user.role;
}
return session;
},
},
// Configure one or more authentication providers
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
// ...add more providers here
],
secret: env.NEXTAUTH_SECRET,
};
export default NextAuth(authOptions);
When trying to login in dev environment I also get the error:
Invalid `p.account.create()` invocation in
<adress here which I deleted>
16 },
17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),
18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create(
The provided value for the column is too long for the column's type. Column: for
[next-auth][error][adapter_error_linkAccount]
https://next-auth.js.org/errors#adapter_error_linkaccount
Invalid `p.account.create()` invocation in
Note that I dont get anything in the error for the Column, I wish I new what column it is talking about.
If you know whats going on pls help, and thanks.