Next.js Discord

Discord Forum

Unknown Argument provider_providerAccountId

Answered
SpicyJungle posted this in #help-forum
Open in Discord
I'm getting an error with authjs and prisma, using github oauth.

Unknown argument `provider_providerAccountId`. Did you mean `providerId_providerAccountId`? Available options are marked with ?. PrismaClientValidationError:
Invalid `prisma.account.findUnique()` invocation:

{
  where: {
    provider_providerAccountId: {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
      providerAccountId: "45978658",
      provider: "github"
    },
?   id?: String,
?   providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
?   AND?: AccountWhereInput | AccountWhereInput[],

...


These are my callbacks:
        async session({token,session}) {
            console.log("SESSION", token, session)
            if (token) {
                session.user.id = token.id
                session.user.name = token.name
                session.user.image = token.picture
                session.user.email = token.email
            }

            return session;
        },
        async jwt({token, user}) {
            console.log("JWT", token, user)
            const dbUser = await db.user.findFirst({
                where: {
                    email: token.email
                }
            });

            if (!dbUser) {
                token.id = user!.id;
                return token;
            }

            return {
                id: dbUser.id,
                name: dbUser.name,
                email: dbUser.email,
                image: dbUser.image
            }
        },
Answered by Ray
the link you sent is for v3
View full answer

11 Replies

your prisma schema is incorrect
@Ray your prisma schema is incorrect
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
  relationMode = "prisma"
}

model Account {
  id                 String    @id @default(cuid())
  userId             String
  providerType       String
  providerId         String
  providerAccountId  String
  refreshToken       String?
  accessToken        String?
  accessTokenExpires DateTime?
  createdAt          DateTime  @default(now())
  updatedAt          DateTime  @updatedAt
  user               User      @relation(fields: [userId], references: [id])

  @@unique([providerId, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  userId       String
  expires      DateTime
  sessionToken String   @unique
  accessToken  String   @unique
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
  user         User     @relation(fields: [userId], references: [id])
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  accounts      Account[]
  sessions      Session[]
}
This is the schema, i cant tell whats wroong/different from the https://next-auth.js.org/v3/adapters/prisma
So I just replaced providerId with provider in the schema, and now I get a different error:
Argument `providerType` is missing. PrismaClientValidationError:
Invalid `prisma.account.create()` invocation:

{
  data: {
    provider: "github",
    type: "oauth",
    providerAccountId: "45978658",
    access_token: "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",
    token_type: "bearer",
    scope: "read:user,user:email",
    userId: "clpbe29wl0000agsggnwjlkmw",
+   providerType: String
  }
}


Though providerType is on the schema
model Account {
  id                 String    @id @default(cuid())
  userId             String
  providerType       String
  provider         String
  providerAccountId  String
  refreshToken       String?
  accessToken        String?
  accessTokenExpires DateTime?
  createdAt          DateTime  @default(now())
  updatedAt          DateTime  @updatedAt
  user               User      @relation(fields: [userId], references: [id])

  @@unique([provider, providerAccountId])
}
Very hacky but I made the providerType optional and now I get a oauthaccountnotlinked callback
and none of my console logs in jwt and session callbacks trigger
Bumping this. I used prisma studio to wipe all the tables and now I first get a

https://next-auth.js.org/errors#oauth_callback_handler_error
Invalid `prisma.account.create()` invocation:

{
  data: {
    provider: "github",
    type: "oauth",
    ~~~~
    providerAccountId: "45978658",
    access_token: "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",
    token_type: "bearer",
    scope: "read:user,user:email",
    userId: "clpcgzrjn000058yiy9j03ckj",
?   id?: String,
?   providerType?: String | Null,
?   refreshToken?: String | Null,
?   accessToken?: String | Null,
?   accessTokenExpires?: DateTime | Null,
?   createdAt?: DateTime,
?   updatedAt?: DateTime
  }
}

Unknown argument `type`. Available options are marked with ?. PrismaClientValidationError:

This adds a record to the user table, but no sessions or anything.
Then when I try to authorize again, I get the oauthaccountnotlinked error
the link you sent is for v3
Answer
@Ray https://authjs.dev/reference/adapter/prisma
thank you, appears to work