codestates / codestates/UDONDAM
[๐งError_log] ์ด์ ์ / 2021-12-10
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
> ### ์ด๋ค ์๋ฌ์ธ๊ฐ์?
> `clearCookie('jwt')`๊ฐ ํตํ์ง ์์์ /logout์ ํ์ ๋ ์ฌ์ดํธ์ ์กด์ฌํ๋ cookies๊ฐ ์ฌ๋ผ์ง์ง ์์.
> ์๋ฒ ์ชฝ์์ req.cookies ๋ฅผ ์จ๋ ์ฟ ํค๊ฐ ๋ณด์ด์ง ์์. `[Object: null prototype] {}`๊ฐ ๋ธ.
> ### ์๋ฌ ๋ฉ์์ง
> ์๋ฌ ๋ฉ์ธ์ง๋ ์์
>
> ### ์๋ฌ ํธ๋ค๋ง ๋ฐฉ๋ฒ
> * ์ฐ๋ฆฌ๋ ๋ก๊ทธ์์ ์์ฒญ์ POST > /logout ์ ํ๋ค. ๊ทธ๋ฌ๋ ๊ทธ๋ฌ๋ฉด ์ ๋๋ค. GET > /logout ์ ํด์ผ์ง๋ง req.cookies๋ ๋จ๊ณ clearCookie ๋ช
๋ น์ด๋ ํตํ๋ค.
> ใด ์ฆ GET > /logout ์ผ๋ก axios๋ฅผ ๋ณด๋ด์ผ๋ง ์๋ฒ ์ชฝ์์๋ req.cookies ๊ฐ ๋จ๋ฉด์ clearCookie๋ก ์ฌ์ดํธ์ ์กด์ฌํ๋ ์ฟ ํค๋ฅผ ์ง์ธ ์ ์์๋ค.
>
> ```js
> // server > router > auth.js
> // router.post >> router.get
> router.get('/logout',authRouter.logout);
>
> // server > controllers > auth.js
> // not change
> logout: async (req, res) => {
> console.log(req.cookies)
> try {
> res.clearCookie('jwt');
> res.status(200).json({"message": "logout!"});
> return;
> }
> catch (err) {
> console.log(err);
> return res.status(401).json({ "message": "Unauthorized"});
> }
> }
>
> // client > src > pages > Mypage.tsx
> // axios.post >> axios.get
> await axios.get(`${process.env.REACT_APP_API_URL}/logout`, { withCredentials: true })
> ```
>
> ### ์๋ฌ ํธ๋ค๋ง์ ์ํด ์ฐธ๊ณ ํ ๋ ํผ๋ฐ์ค ๋งํฌ
> ์์
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.