inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

마이히님의 게시글

마이히 마이히

@myheee

수강평 작성수
6
평균평점
5.0

게시글 1

질문&답변

로그아웃 401 에러(Unauthorized)

2가지를 수정하였더니 해결이 되었습니다 ! 로그인 시 쿠키 설정 확인 - path , domain , secure , sameSite 등의 기본값이 적용되므로 확인 필요 app.post('/api/users/login', async (req, res) => { // ... 생략 const tokenUser = await user.generateToken(); res.cookie("x_auth", tokenUser.token, { httpOnly: true, secure: false, sameSite: 'lax', path: '/' }) .status(200) .json({ loginSuccess: true, userId: user._id }); } catch (err) { return res.status(400).send(err); } }); 로그아웃 시 쿠키 전송 확인 - withCredentials: true 를 올바르게 사용 const onClickHandler = () => { axios.post('http://localhost:5000/api/users/logout', {}, { withCredentials: true }) .then(response => { //.. 생략 }); }; 혹시나 로그아웃에 헤매고 계시다면 조금이나마 도움이 되었으면 합니다 😄 완강까지 모두 화이팅이에요 !

좋아요수
0
댓글수
2
조회수
520