[해결법] Error: req#logout requires a callback function
1931
에러 나오는 이유
passport.js 버전이 올라감에 따라 사용법에 변경이 있었기 때문입니다.
해결법
아래와 같이 코드를 변경하면 정상동작합니다.
router.get('/logout', (req, res, next) => {
req.logOut(err => {
if (err) {
return next(err);
} else {
console.log('로그아웃됨.');
res.redirect('/');
}
});
});
자세한 설명
https://medium.com/passportjs/fixing-session-fixation-b2b68619c51d
위 포스트에서 내용 일부발췌하여 간단한 번역을 덧붙여둡니다.
The other major change is that that req.logout() is now an asynchronous function, whereas previously it was synchronous. For instance, a logout route that was previously:
이번 업데이트로 원래는 동기 함수였던 req.logout()이 비동기 함수가 됐습니다. 바로 아래의 코드는 동기함수였을 시절 쓰던 방식입니다.
app.post('/logout', function(req, res, next) {
req.logout();
res.redirect('/');
});should be modified to:
이젠 위 코드처럼 쓰지 말고, 아래처럼 써야 잘 동작합니다.
app.post('/logout', function(req, res, next) {
req.logout(function(err) {
if (err) { return next(err); }
res.redirect('/');
});
});
...
This improves the overall security posture of any app using Passport for authentication.
바뀐 사용법은 보안(security)상의 이점이 있습니다.
답변 1
보충 강의 감사합니다
0
396
0
공부 순서 고민
0
574
1
update 함수 문의
0
408
0
도대체 다들 공부는 어떻게 하시는 건가요?
0
553
2
테스트를 위한 객체 오류와 createQueryBuilder 사용 방법 질문있습니다!
0
535
1
디테일 메인페이지에서 상세페이지로 가는 링크 부분
0
445
0
nestjs s3 파일업로드 진행중인데 Buffer속성이 없어요
0
604
0
swr 구현 질문입니다.
1
700
2
힘이 듭니다
0
591
1
Ubuntu 설치 시
0
811
0
최신 버전 업데이트 요청 건
0
540
1
[정보공유] next13일 경우 `className` did ont match. 오류 발생 시 해결법
0
1254
0





