inflearn logo
Course

Course

Instructor

myheee's Posts

myheee myheee

@myheee

Reviews Written
6
Average Rating
5.0

Posts 1

Q&A

로그아웃 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 => { //.. 생략 }); }; 혹시나 로그아웃에 헤매고 계시다면 조금이나마 도움이 되었으면 합니다 😄 완강까지 모두 화이팅이에요 !

Likes
0
Comments
2
Viewcount
547