2013-01-07 2 views

답변

61

어디서나 쉽게 발견 할 수있는 것은 아니지만 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 
}); 
+1

위의 예는 문제의 몇 가지가 있습니다. 3 번 줄은'if (req.isAuthenticated())'이어야하고 9 번 줄은'..., ensureAuthenticated, ...'여야합니다. 더 좋은 예를 보려면 다음을 확인하십시오. https://github.com/jaredhanson/passport-local/blob/master/examples/express3-mongoose/app.js – chris

+1

@chris 메모 주셔서 감사합니다. 위의 문제를 해결했습니다. –

+1

이 작업을하려면 "return next()"라고 써야했습니다. – Elisabeth

관련 문제