nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
25.05k stars 3.54k forks source link

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

Closed darshil89 closed 6 months ago

darshil89 commented 6 months ago

Adapter type

@auth/prisma-adapter

Environment

{ "name": "website", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@next-auth/prisma-adapter": "^1.0.7", "@prisma/client": "^5.13.0", "next": "14.2.3", "react": "^18", "react-dom": "^18", "react-icons": "^5.2.0" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", "eslint-config-next": "14.2.3", "postcss": "^8", "prisma": "^5.13.0", "tailwindcss": "^3.4.1", "typescript": "^5" } }

Reproduction URL

http://localhost:3000/

Describe the issue

On providing the google signin using next auth I am getting the prisma error that is -

[next-auth][error][adapter_error_getUserByAccount] https://next-auth.js.org/errors#adapter_error_getuserbyaccount Invalid prisma.account.findUnique() invocation:

{ where: { provider_providerAccountId: {

      providerAccountId: "108569757528954113037",
      provider: "google"
    },
?   id?: String,
?   providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
?   AND?: AccountWhereInput | AccountWhereInput[],
?   OR?: AccountWhereInput[],
?   NOT?: AccountWhereInput | AccountWhereInput[],
?   userId?: StringFilter | String,
?   providerType?: StringFilter | String,
?   providerId?: StringFilter | String,
?   providerAccountId?: StringFilter | String,
?   refreshToken?: StringNullableFilter | String | Null,
?   accessToken?: StringNullableFilter | String | Null,
?   accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,
?   createdAt?: DateTimeFilter | DateTime,
?   updatedAt?: DateTimeFilter | DateTime,
?   user?: UserRelationFilter | UserWhereInput
  },
  select: {
    user: true
  }
}

Unknown argument `provider_providerAccountId`. Did you mean `providerId_providerAccountId`? Available options are marked with ?. {
  message: '\n' +
    'Invalid `prisma.account.findUnique()` invocation:\n' +
    '\n' +
    '{\n' +
    '  where: {\n' +
    '    provider_providerAccountId: {\n' +
    '    ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
    '      providerAccountId: "108569757528954113037",\n' +
    '      provider: "google"\n' +
    '    },\n' +
    '?   id?: String,\n' +
    '?   providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,\n' +
    '?   AND?: AccountWhereInput | AccountWhereInput[],\n' +
    '?   OR?: AccountWhereInput[],\n' +
    '?   NOT?: AccountWhereInput | AccountWhereInput[],\n' +
    '?   userId?: StringFilter | String,\n' +
    '?   providerType?: StringFilter | String,\n' +
    '?   providerId?: StringFilter | String,\n' +
    '?   providerAccountId?: StringFilter | String,\n' +
    '?   refreshToken?: StringNullableFilter | String | Null,\n' +
    '?   accessToken?: StringNullableFilter | String | Null,\n' +
    '?   accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,\n' +
    '?   createdAt?: DateTimeFilter | DateTime,\n' +
    '?   updatedAt?: DateTimeFilter | DateTime,\n' +
    '?   user?: UserRelationFilter | UserWhereInput\n' +
    '  },\n' +
    '  select: {\n' +
    '    user: true\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Unknown argument `provider_providerAccountId`. Did you mean `providerId_providerAccountId`? Available options are marked with ?.',
  stack: 'PrismaClientValidationError: \n' +
    'Invalid `prisma.account.findUnique()` invocation:\n' +
    '\n' +
    '{\n' +
    '  where: {\n' +
    '    provider_providerAccountId: {\n' +
    '    ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
    '      providerAccountId: "108569757528954113037",\n' +
    '      provider: "google"\n' +
    '    },\n' +
    '?   id?: String,\n' +
    '?   providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,\n' +
    '?   AND?: AccountWhereInput | AccountWhereInput[],\n' +
    '?   OR?: AccountWhereInput[],\n' +
    '?   NOT?: AccountWhereInput | AccountWhereInput[],\n' +
    '?   userId?: StringFilter | String,\n' +
    '?   providerType?: StringFilter | String,\n' +
    '?   providerId?: StringFilter | String,\n' +
    '?   providerAccountId?: StringFilter | String,\n' +
    '?   refreshToken?: StringNullableFilter | String | Null,\n' +
    '?   accessToken?: StringNullableFilter | String | Null,\n' +
    '?   accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,\n' +
    '?   createdAt?: DateTimeFilter | DateTime,\n' +
    '?   updatedAt?: DateTimeFilter | DateTime,\n' +
    '?   user?: UserRelationFilter | UserWhereInput\n' +
    '  },\n' +
    '  select: {\n' +
    '    user: true\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Unknown argument `provider_providerAccountId`. Did you mean `providerId_providerAccountId`? Available options are marked with ?.\n' +
    '    at Tn (C:\\Web Development\\Nextjs13.4\\one-stop-for-students\\website\\node_modules\\@prisma\\client\\runtime\\library.js:115:6855)\n' +
    '    at In.handleRequestError (C:\\Web Development\\Nextjs13.4\\one-stop-for-students\\website\\node_modules\\@prisma\\client\\runtime\\library.js:122:6510)\n' +
    '    at In.handleAndLogRequestError (C:\\Web Development\\Nextjs13.4\\one-stop-for-students\\website\\node_modules\\@prisma\\client\\runtime\\library.js:122:6188)\n' +
    '    at In.request (C:\\Web Development\\Nextjs13.4\\one-stop-for-students\\website\\node_modules\\@prisma\\client\\runtime\\library.js:122:5896)\n' +
    '    at async l (C:\\Web Development\\Nextjs13.4\\one-stop-for-students\\website\\node_modules\\@prisma\\client\\runtime\\library.js:127:11167)\n' +
    '    at async getUserByAccount (webpack-internal:///(rsc)/./node_modules/@next-auth/prisma-adapter/dist/index.js:211:29)',
  name: 'PrismaClientValidationError'
}
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
https://next-auth.js.org/errors#oauth_callback_handler_error
Invalid `prisma.account.findUnique()` invocation:

{
  where: {
    provider_providerAccountId: {
  providerAccountId: "108569757528954113037",
  provider: "google"
},

? id?: String, ? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput, ? AND?: AccountWhereInput | AccountWhereInput[], ? OR?: AccountWhereInput[], ? NOT?: AccountWhereInput | AccountWhereInput[], ? userId?: StringFilter | String, ? providerType?: StringFilter | String, ? providerId?: StringFilter | String, ? providerAccountId?: StringFilter | String, ? refreshToken?: StringNullableFilter | String | Null, ? accessToken?: StringNullableFilter | String | Null, ? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null, ? createdAt?: DateTimeFilter | DateTime, ? updatedAt?: DateTimeFilter | DateTime, ? user?: UserRelationFilter | UserWhereInput }, select: { user: true } }

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

{ where: { provider_providerAccountId: {


      providerAccountId: "108569757528954113037",
      provider: "google"
    },
?   id?: String,
?   providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
?   AND?: AccountWhereInput | AccountWhereInput[],
?   OR?: AccountWhereInput[],
?   NOT?: AccountWhereInput | AccountWhereInput[],
?   userId?: StringFilter | String,
?   providerType?: StringFilter | String,
?   providerId?: StringFilter | String,
?   providerAccountId?: StringFilter | String,
?   refreshToken?: StringNullableFilter | String | Null,
?   accessToken?: StringNullableFilter | String | Null,
?   accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,
?   createdAt?: DateTimeFilter | DateTime,
?   updatedAt?: DateTimeFilter | DateTime,
?   user?: UserRelationFilter | UserWhereInput
  },
  select: {
    user: true
  }
}

Unknown argument `provider_providerAccountId`. Did you mean `providerId_providerAccountId`? Available options are marked with ?.
    at Tn (C:\Web Development\Nextjs13.4\one-stop-for-students\website\node_modules\@prisma\client\runtime\library.js:115:6855)
    at In.handleRequestError (C:\Web Development\Nextjs13.4\one-stop-for-students\website\node_modules\@prisma\client\runtime\library.js:122:6510)
    at In.handleAndLogRequestError (C:\Web Development\Nextjs13.4\one-stop-for-students\website\node_modules\@prisma\client\runtime\library.js:122:6188)
    at In.request (C:\Web Development\Nextjs13.4\one-stop-for-students\website\node_modules\@prisma\client\runtime\library.js:122:5896)
    at async l (C:\Web Development\Nextjs13.4\one-stop-for-students\website\node_modules\@prisma\client\runtime\library.js:127:11167)
    at async getUserByAccount (webpack-internal:///(rsc)/./node_modules/@next-auth/prisma-adapter/dist/index.js:211:29) {
  name: 'GetUserByAccountError',
  code: undefined
}
 GET /api/auth/callback/google?state=BfjaMhiq1Tk1qJroQme0gRgMqgeH0TAPlzAn7StfSyw&code=4%2F0AdLIrYd06X_9T4aLux5FnGD5Vwu3lR8kAAC8U-kMgLBULxDv1TXHx0fUeCh3ZnPx1I-taw&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=consent 302 in 498ms
 GET /api/auth/error?error=Callback 302 in 33ms
 GET /api/auth/signin?error=Callback 200 in 14ms

### How to reproduce

### install next js , next auth and prisma and write the below code in the respective directory

**PRISMA**

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model Account {
  id                 String    @id @default(auto()) @map("_id") @db.ObjectId
  userId             String    @db.ObjectId
  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(auto()) @map("_id") @db.ObjectId
  userId       String   @db.ObjectId
  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(auto()) @map("_id") @db.ObjectId
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  account       Account[]
  sessions      Session[]
}

model VerificationRequest {
  id         String   @id @default(auto()) @map("_id") @db.ObjectId
  identifier String
  token      String   @unique
  expires    DateTime
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  @@unique([identifier, token])
}

**next auth**
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { NextAuthOptions } from "next-auth";
import { PrismaClient } from "@prisma/client";
import { PrismaAdapter } from "@next-auth/prisma-adapter";

const prisma = new PrismaClient();

const authOptions: NextAuthOptions = {
  adapter: PrismaAdapter(prisma),

  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    }),
  ],
  session: {
    strategy: "jwt",
  },
  secret: process.env.SECRET,
};
const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

### Expected behavior

I should be enabled to provide google auth in my application
github-actions[bot] commented 6 months ago

We could not detect a valid reproduction link. Make sure to follow the bug report template carefully.

Why was this issue closed?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We need a link to a public GitHub repository. Example: (NextAuth.js example repository).

The bug template that you filled out has a section called "Reproduction URL", which is where you should provide the link to the reproduction.

What should I do?

Depending on the reason the issue was closed, you can do the following:

In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.

My repository is private and cannot make it public

In most cases, a private repo will not be a sufficient minimal reproduction, as this codebase might contain a lot of unrelated parts that would make our investigation take longer. Please do not make it public. Instead, create a new repository using the templates above, adding the relevant code to reproduce the issue. Common things to look out for:

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps by opening a new issue.

I think my reproduction is good enough, why aren't you looking into it quickly?

We look into every issue and monitor open issues for new comments.

However, sometimes we might miss a few due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources