我正在遵循 Next.js 提供的示例repo 来实现 Passport.JS 和下一个连接。
我有一个表单提交处理程序,它在验证后发送电子邮件和密码。
我正在使用 axios:
import axios from 'axios';
export default function loginSubmit(
email,
password,
) {
const loginData = {
email,
password,
};
axios
.post(`/api/signin`, {
params: loginData,
withCredentials: true,
headers: {
'Content-Type': 'application/json'
},
})
.then(response => {
})
.catch((error) => {
if (error.response) {
console.log("error.response ", error.response);
} else if (error.request) {
console.log("error.request ", error.request);
} else if (error.message) {
// do something other than the other two
}
}
我已经进行了研究,并且400 Bad request意味着错误出在客户端上。
一些想法是检查 URL,在终端中刷新 DNS,清除 cookie。但这些都不起作用。
这是 get 返回的错误:
error.response : {
"data": "Bad Request",
"status": 400,
"statusText": "Bad Request",
"headers": {
"connection": "keep-alive",
"content-length": "11",
"date": "Sat, 16 Oct 2021 18:49:44 GMT",
"keep-alive": "timeout=5"
},
"config": {
"url": "/api/signin",
"method": "post",
"data": "{\"params\":{\"email\":\"xxxxxx@gmail.com\",\"password\":\"Aug8162016!\"},\"withCredentials\":true,\"headers\":{\"Content-Type\":\"application/json\"},\"credentials\":\"same-origin\"}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json"
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
}
},
"request": {}
}
我的直觉告诉我这里有东西。
有什么想法可以让我得到更严重的错误吗?