我已经更新了Nextjs到它的最新版本,还更新了文档中指定的next-auth和prisma适配器。
但是,当我尝试在应用程序中使用signIn
进行身份验证时,我在最新更新中遇到以下错误:
[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'
}
是我做错了什么,还是我错过了什么不相容的地方?
相关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);
},
},
});
3条答案
按热度按时间niwlg2el1#
终于解决了这个问题。由于next-auth已经移动到monorepo,更新包是不够的,你需要先卸载它,然后再安装它。
运行:
然后:
这为我修好了。
7xzttuei2#
在NextAuth.JS 4.0中,“Prisma模式”略有变化。
从升级指南:
created_at
/createdAt
和updated_at
/updatedAt
字段从所有模型中删除。user_id
/userId
一致命名为userId
。compound_id
/compoundId
已从帐户中删除。access_token
/accessToken
已从会话中删除。email_verified
/emailVerified
始终命名为email_verified
。provider_id
/providerId
重命名为帐户上的提供商provider_type
/providerType
重命名为“帐户”类型provider_account_id
/providerAccountId
始终命名为providerAccountId
expires_in
的access_token_expires
/accessTokenExpires
expires_at
、token_type
、scope
、id_token
、session_state
verification_requests
表已重命名为verification_tokens
在以下位置完成新架构:https://next-auth.js.org/adapters/prisma
yebdmbv43#
我的版本:“@next-auth/prisma-adapter”:“^1.0.5”,“next-auth”:“^4.21.1”,
我已经解决了这个错误,卸载@next-auth/prisma-adapter next-auth,然后再次安装@next-auth/prisma-adapter next-auth