【发布时间】:2021-08-19 17:45:01
【问题描述】:
我正在使用护照本地策略来启用用户登录。 早些时候,我的后端代码是 -
passport.authenticate('local', {
successRedirect : '/dashboard',
failureRedirect : '/users/login',
failureFlash : true
})(req, res, next)
后来,我实现了一个 google recaptcha(需要使用 jquery/JS 的自定义回调函数)。如下-
document.getElementById("login-form").addEventListener('submit', submitForm)
function submitForm(e){
e.preventDefault()
const email = $("#email").val()
const password = $("#password").val()
const captcha = $("#g-recaptcha-response").val()
fetch('/users/login', {
method:'POST',
headers:{
'Accept': 'application/json, text/plain, */*',
'Content-type': 'application/json'
},
body: JSON.stringify({email:email,password:password, captcha:captcha})
})
.then(response=>{
console.log(response)
if (response.redirected) {
window.location.href = response.url;
}
else{
}
})
.catch(function(err) {
console.info(err + " url: " + url);
});
现在,在实现自定义回调之前,护照自动显示缺少凭据闪烁消息以防字段为空,但是,现在我正在使用自定义回调,记录了以下数据。我不知道如何显示快讯。请忽略代码中包含js和jquery以及function()和()=>{}等意义上的不一致。
Response {type: "basic", url: "http://localhost:3000/users/login", redirected: false, status: 200, ok: true, …}
body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://localhost:3000/users/login"
__proto__: Response
【问题讨论】:
标签: javascript jquery node.js promise passport-local