我正在使用登錄腳本的 WebDevSimplifieds 版本。到目前為止它的作業,但我現在被困在一個我想在登錄后重定向之前運行的功能。
用戶在登錄頁面上輸入所有憑據,如果一切正確,用戶將被重定向到 index.ejs(html)。在重定向之前,我想運行一個函式,該函式根據用戶在特定欄位中輸入的內容更改服務器變數。
這是有效的,但當然沒有額外的功能。
app.post(
'/login',
checkNotAuthenticated,
passport.authenticate('local',
{
successRedirect: '/',
failureRedirect: '/login',
failureFlash: true,
}
)
)
我想擁有這樣的東西。console.log 命令有效,但 passport.authenticate 無效。
app.post(
'/login',
checkNotAuthenticated, (req, res) => {
console.log("that works");
passport.authenticate('local',
{
successRedirect: '/',
failureRedirect: '/login',
failureFlash: true,
}
)}
)
uj5u.com熱心網友回復:
passport.authenticate回傳具有簽名的函式(req, res, next),即中間件。
比較源代碼:
module.exports = function authenticate(passport, name, options, callback) {
// ...
return function authenticate(req, res, next) {
// ...
};
// ...
};
您需要呼叫該函式。
app.post(
'/login',
checkNotAuthenticated,
(req, res, next) => {
console.log("that works");
const authFunc = passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login',
failureFlash: true,
});
authFunc(req, res, next);
)}
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/424357.html
