[passport] req#logout requires a callback function 오류 해결

2023. 2. 28. 03:19·Trouble Shooting
반응형

Passport Version 0.6.0

패키지를 최신 버전으로 업그레이드하면서 기존에 잘 작동했던 passport 코드에서 오류가 발생했다.

^0.5.3 -> ^0.6.0

 

기존에는 아래와 같이 사용했었다.

userRouter.get('/logout', (req, res) => {
  req.logout();
  res.clearCookie('token');
  res.redirect(req.get('Referrer'));
});

 

 

 

 

passport 0.6.0버전 업데이트 내용을 보면 기존의 req.logout()은 동기적으로 작동했지만, 0.6.0 이후로는 비동기 함수가 되었다. 따라서 콜백함수를 logout에 넘겨주는 방식으로 써주면 된다.

userRouter.get('/logout', (req, res) => {
  req.logout(function () {
    res.clearCookie('token');
    res.redirect(req.get('Referrer'));
  });
});

 

References

https://www.passportjs.org/tutorials/password/logout/

https://medium.com/passportjs/fixing-session-fixation-b2b68619c51d

https://stackoverflow.com/questions/72336177/error-reqlogout-requires-a-callback-function

 

반응형

'Trouble Shooting' 카테고리의 다른 글

yarn unknown workspace 오류 해결  (0) 2023.05.23
Delete `␍`eslint(prettier/prettier) 해결하기  (0) 2023.05.18
[Next.js] Component selectors can only be used in conjunction with @emotion/babel-plugin 해결  (0) 2023.02.23
[Github Actions] the process '/usr/bin/git' failed with exit code 128 해결  (0) 2023.02.21
[Nginx] 페이지 새로고침 시 Page Not Found 오류 해결  (1) 2023.02.07
'Trouble Shooting' 카테고리의 다른 글
  • yarn unknown workspace 오류 해결
  • Delete `␍`eslint(prettier/prettier) 해결하기
  • [Next.js] Component selectors can only be used in conjunction with @emotion/babel-plugin 해결
  • [Github Actions] the process '/usr/bin/git' failed with exit code 128 해결
SH_Roh
SH_Roh
  • SH_Roh
    혼자공부끄적끄적
    SH_Roh
  • 전체
    오늘
    어제
    • 분류 전체보기 (159)
      • FE (39)
        • HTML, CSS (3)
        • Javascript (17)
        • React (11)
        • Next.js (4)
      • Network (1)
      • DevOps (4)
      • Git (1)
      • Trouble Shooting (24)
      • Algorithm (41)
        • Python (2)
        • Data Structure, Algorithm (7)
        • Problem Solving (31)
      • Education (23)
        • Elice AI Track (4)
        • Wanted Pre-Onboarding FE Co.. (19)
      • TIL (25)
      • Etc. (1)
        • 회고 (1)
        • 그냥저냥 (0)
  • 링크

    • Github
  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
SH_Roh
[passport] req#logout requires a callback function 오류 해결
상단으로

티스토리툴바