Search code examples
node.jsnext.jsprismanext-auth

Next-auth Invalid `p.account.findUnique()` invocation" on signin with oauth


In my Next.js app, I'm using next-auth for authentication with @next-auth/prisma-adapter and MySQL as the database provider. When i try to sign in with OAuth, I get the following error:

https://next-auth.js.org/errors#adapter_error_getuserbyaccount 
Invalid `p.account.findUnique()` invocation in
/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45

  208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
  209 async getUserByAccount(provider_providerAccountId) {
  210     var _a;
→ 211     const account = await p.account.findUnique(
The column `(not available)` does not exist in the current database. {
  message: '\n' +
    'Invalid `p.account.findUnique()` invocation in\n' +
    '/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45\n' +
    '\n' +
    '  208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),\n' +
    '  209 async getUserByAccount(provider_providerAccountId) {\n' +
    '  210     var _a;\n' +
    '→ 211     const account = await p.account.findUnique(\n' +
    'The column `(not available)` does not exist in the current database.',
  stack: 'Error: \n' +
    'Invalid `p.account.findUnique()` invocation in\n' +
    '/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45\n' +
    '\n' +
    '  208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),\n' +
    '  209 async getUserByAccount(provider_providerAccountId) {\n' +
    '  210     var _a;\n' +
    '→ 211     const account = await p.account.findUnique(\n' +
    'The column `(not available)` does not exist in the current database.\n' +
    '    at Zr.handleRequestError (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:6414)\n' +
    '    at Zr.handleAndLogRequestError (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:5948)\n' +
    '    at Zr.request (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:5786)\n' +
    '    at async t._request (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:174:10455)\n' +
    '    at async getUserByAccount (/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:29)',
  name: 'Error'
}
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR] 
https://next-auth.js.org/errors#oauth_callback_handler_error 
Invalid `p.account.findUnique()` invocation in
/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45

  208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
  209 async getUserByAccount(provider_providerAccountId) {
  210     var _a;
→ 211     const account = await p.account.findUnique(
The column `(not available)` does not exist in the current database. Error: 
Invalid `p.account.findUnique()` invocation in
/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45

  208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
  209 async getUserByAccount(provider_providerAccountId) {
  210     var _a;
→ 211     const account = await p.account.findUnique(
The column `(not available)` does not exist in the current database.
    at Zr.handleRequestError (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:6414)
    at Zr.handleAndLogRequestError (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:5948)
    at Zr.request (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:171:5786)
    at async t._request (/Users/vignesh/projects/bmi-api/node_modules/@prisma/client/runtime/library.js:174:10455)
    at async getUserByAccount (/Users/vignesh/projects/bmi-api/node_modules/@next-auth/prisma-adapter/dist/index.js:211:29) {
  name: 'GetUserByAccountError',
  code: 'P2022'
}

Dependencies

{
"dependencies":{
    "next": "13.4.4",
    "next-auth": "^4.22.1",
    "prisma": "4.11.0",
    "@next-auth/prisma-adapter": "^1.0.7",

}

Project repo https://github.com/alphawhiskey03/bmi-api


Solution

  • I had installed old versions of the packages that I mentioned below.

    1. I updated next-auth, prisma and @prisma/client to their latest versions.
    2. Made sure prisma and @prisma/client are of the same version.
    3. Did yarn prisma db push and yarn prisma generate.

    Everything started working smoothly after this.