41
나는 잠시 동안 찾고 있었고 확실한 문서 소스를 찾지 못했습니다. 이들을 검색 할 때 첫 번째 Google 결과는 StackOverflow입니다."ensureAuthentication" "isAuthenticated"여권 기능에 관한 문서?
더 이상 미들웨어 기능이 있습니까?
나는 잠시 동안 찾고 있었고 확실한 문서 소스를 찾지 못했습니다. 이들을 검색 할 때 첫 번째 Google 결과는 StackOverflow입니다."ensureAuthentication" "isAuthenticated"여권 기능에 관한 문서?
더 이상 미들웨어 기능이 있습니까?
어디서나 쉽게 발견 할 수있는 것은 아니지만 https://github.com/jaredhanson/passport/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js#L74에있는 및 isUnauthenticated
플래그가 Passport 코드에 설정된 위치를 확인할 수 있습니다.
ensureAuthenticated
공식 아니지만, 다음을 통해 구현 될 수 있습니다
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated())
return next();
else
// Return error content: res.jsonp(...) or redirect: res.redirect('/login')
}
app.get('/account', ensureAuthenticated, function(req, res) {
// Do something with user via req.user
});
위의 예는 문제의 몇 가지가 있습니다. 3 번 줄은'if (req.isAuthenticated())'이어야하고 9 번 줄은'..., ensureAuthenticated, ...'여야합니다. 더 좋은 예를 보려면 다음을 확인하십시오. https://github.com/jaredhanson/passport-local/blob/master/examples/express3-mongoose/app.js – chris
@chris 메모 주셔서 감사합니다. 위의 문제를 해결했습니다. –
이 작업을하려면 "return next()"라고 써야했습니다. – Elisabeth