[英]NextAuth fetching api endpoint - req.body undefined
我正在嘗試在我的 NextJS 應用程序中使用 NextAuthJS 進行身份驗證。
我正在使用文檔中的以下代碼
authorize: async(credentials, req)=>{
const res = await fetch("http://localhost:3000/api/userverify",{
method: 'POST',
credentials: "include",
body: JSON.stringify(credentials),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
})
const user = await res.json()
if(res.ok && user){
return user
}
return null
}
問題是實際獲取,在 userverify.js 中我有這段代碼:
export default async function verify(res, req){
const credentials = req.body
console.log(credentials)
const user = await findUser(credentials.email)
if(user){
if(await argon2.verify(req.body.password, user.password)){
res.status(200).send(user)
return user
}
else{
res.status(401).send("Credentials Incorrect")
}
}
}
此文件中的 req.body 未定義,我不使用僅在 api 路由中構建的 express nextjs。
我能做什么?
我認為這是 arguments 的順序。您是否嘗試記錄req
和res
。 第一個參數是request
,第二個是response
:
export default async function verify(req, res){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.