0
我想在用戶登錄時顯示用戶名(function 3
)。最初,我只有function 1
。我已將function 1
更改爲function 2
以顯示登錄用戶的用戶名。我不確定這是否是正確的方法,因爲我不知道是否需要參數res
和next
以及功能next()
。任何想法?如何在NodeJS/ExpressJS /護照中顯示登錄用戶名?
我使用NodeJS
,ExpressJS
和Passport
1.
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
return next()
} else {
res.redirect('/login')
}
}
2.
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
return true
}
return false
}
3.
router.get('/', function(req, res) {
if (isLoggedIn) {
res.render('index', {
username: req.user.username
})
} else {
res.render('index')
}
})
我看到我忘了添加參數。非常感謝你! :) – Engo