在下面的代碼中,我試圖將其發送到登錄頁面,但它不起作用。
app.get('/current-pass', (req, res) => {
res.sendFile(path.join(staticPath, "currentPass.html"));
})
app.post('/current-pass', (req, res) => {
let { email, cpassword } = req.body;
if(cpassword.value){
return res.json({ 'alert': "please enter your current password"});
}
db.collection('users').doc(email).get()
.then(user => {
bcrypt.compare(cpassword, user.data().password, (err, result) => {
if(result){
let data = user.data();
return res.json({
location.href = "/login"; // This is not working
})
} else{
return res.json({'alert': 'current password is incorrect'});
}
})
})
})
所有代碼都可以正常作業,但location.href無法正常作業。代替,
return res.json({
location.href = "/login";
})
我用了,
return res.send('success');
但它也不起作用
uj5u.com熱心網友回復:
您可以使用res.redirect('/login');Express.js 進行重定向。請求中沒有location變數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/512286.html
標籤:Google Cloud Collective javascripthtml节点.js火力基地npm
上一篇:403Forbidden-PUThttps://registry.npmjs.org/shah-您無權發布“shah”。您是否以正確的用戶身份登錄?
下一篇:如何修復npm缺少的腳本:“i”
