ped*_*nna 5 jwt strapi next.js next-auth
[我正在使用 Next.js (11.1.2) + NextAuth (4.0.0-beta.7) 登录 Strapi API,仅使用凭证提供程序 (JWT)。]
整个身份验证流程正在“工作” [...nextauth].js:
import NextAuth from "next-auth"
import CredentialsProvider from 'next-auth/providers/credentials'
export default NextAuth({
providers: [
CredentialsProvider({
name: 'AppName',
credentials: {
email: {label: "Email", type: "text", placeholder: "daveglow@foomail.com"},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
const res = await fetch(process.env.CREDENTIALS_AUTH_URL, {
method: 'POST',
body: JSON.stringify(credentials),
headers: { "Content-Type": "application/json" }
})
const user = await res.json()
if (res.ok && user) {
return user
}
return null
}
})
],
session: {
strategy: "jwt",
maxAge: 30 * 24 * 60 * 60 // 30 days
},
pages: {
signIn: '/signin',
signOut: '/signin',
error: '/signin'
},
})
Run Code Online (Sandbox Code Playgroud)
但用户登录后几秒钟,终端显示此消息并删除会话:
[next-auth][warn][NO_SECRET] https://next-auth.js.org/warnings#no_secret
[next-auth][error][JWT_SESSION_ERROR] https://next-auth.js.org/errors#jwt_session_error decryption operation failed {
message: 'decryption operation failed',
stack: 'JWEDecryptionFailed: decryption operation failed\n'
Run Code Online (Sandbox Code Playgroud)
所以,我尝试添加:
secret: process.env.SECRET, //I've created using $ openssl rand -base64 32
Run Code Online (Sandbox Code Playgroud)
然后我收到两条不同的消息
浏览器控制台:
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error
Run Code Online (Sandbox Code Playgroud)
VS 代码终端:
[next-auth][error][CALLBACK_CREDENTIALS_JWT_ERROR]
https://next-auth.js.org/errors#callback_credentials_jwt_error Signin in with credentials only supported if JWT strategy is enabled UnsupportedStrategy [UnsupportedStrategyError]: Signin in with credentials only supported if JWT strategy is enabled
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的选择,但它太混乱了。现在,我不知道该怎么办。:( 你能帮助我吗?
| 归档时间: |
|
| 查看次数: |
10070 次 |
| 最近记录: |