Reputation: 138
I've updated Nextjs to it's newest version and also updated next-auth and the prisma adapter as specified by the docs.
However, when I try to authenticate in the app with signIn
I get the following error with the latest updates:
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
https://next-auth.js.org/errors#oauth_callback_handler_error getUserByAccount is not a function {
message: 'getUserByAccount is not a function',
stack: 'TypeError: getUserByAccount is not a function\n' +
' at Object.callback (/home/.../node_modules/next-auth/core/routes/callback.js:81:39)\n' +
' at runMicrotasks (<anonymous>)\n' +
' at processTicksAndRejections (internal/process/task_queues.js:95:5)\n' +
' at async NextAuthHandler (/home/.../node_modules/next-auth/core/index.js:103:28)\n' +
' at async NextAuthNextHandler (/home/.../node_modules/next-auth/next/index.js:40:7)\n' +
' at async [...]/node_modules/next-auth/next/index.js:80:32\n' +
' at async Object.apiResolver (/home/.../node_modules/next/dist/server/api-utils.js:102:9)\n' +
' at async DevServer.handleApiRequest (/home/.../node_modules/next/dist/server/next-server.js:1014:9)\n' +
' at async Object.fn (/home/.../node_modules/next/dist/server/next-server.js:901:37)\n' +
' at async Router.execute (/home/.../node_modules/next/dist/server/router.js:210:32)',
name: 'TypeError'
}
Is there something I'm doing wrong, or is there an incompatibility I'm missing?
Relevant package.json
:
...
"@next-auth/prisma-adapter": "^0.5.2-next.19",
"next": "^12.0.3",
"next-auth": "4.0.0-beta.6",
"prisma": "^3.4.1",
...
[...nextauth].ts
:
import NextAuth from 'next-auth';
import CognitoProvider from 'next-auth/providers/cognito';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export default NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
CognitoProvider({
clientId: process.env.COGNITO_CLIENT_ID,
clientSecret: process.env.COGNITO_CLIENT_SECRET,
issuer: process.env.COGNITO_ISSUER,
}),
],
callbacks: {
async session({ session, user }) {
session.userId = user.id;
session.role = user.role;
return Promise.resolve(session);
},
},
});
Upvotes: 10
Views: 9844
Reputation: 1
I had similar problem. I still don't understand how, but dropping Account model from MongoDB, then executing this command npx prisma db push
resolved my issue.
Upvotes: 0
Reputation: 1
I solved this problem using the following:
$ npm uninstall next-auth @next-auth/prisma-adapter
$ npm install @next-auth/prisma-adapter next-auth
Upvotes: 0
Reputation: 1
I used "debug:process.env.NODE_ENV ==='development'", and worked just fine
Upvotes: 0
Reputation: 21
my version: "@next-auth/prisma-adapter": "^1.0.5", "next-auth": "^4.21.1",
i have resolved the error, uninstall @next-auth/prisma-adapter next-auth, and install @next-auth/prisma-adapter next-auth again
Upvotes: 2
Reputation: 2820
Finally resolved the problem. Since next-auth has moved to monorepo, updating package was not enough, you need to uninstall it first then install it again.
Run:
npm uninstall next-auth @next-auth/prisma-adapter
then:
npm install @next-auth/prisma-adapter
This fixed it for me.
Upvotes: 14
Reputation: 41
In the NextAuth.JS 4.0 the "Prisma schema" have slightly changed.
From the upgrade guide:
created_at
/createdAt
andupdated_at
/updatedAt
fields are removed from all Models.user_id
/userId
consistently nameduserId
.compound_id
/compoundId
is removed from Account.access_token
/accessToken
is removed from Session.email_verified
/emailVerified
on User is consistently namedemail_verified
.provider_id
/providerId
renamed to provider on Accountprovider_type
/providerType
renamed to type on Accountprovider_account_id
/providerAccountId
on Account is consistently namedproviderAccountId
access_token_expires
/accessTokenExpires
on Account renamed toexpires_in
- New fields on Account:
expires_at
,token_type
,scope
,id_token
,session_state
verification_requests
table has been renamed toverification_tokens
Complete new schema in: https://next-auth.js.org/adapters/prisma
Upvotes: 3