Skip to content

Commit

Permalink
fix: 쿠키값 삭제는 loggedin, 없다면 /으로 라우팅
Browse files Browse the repository at this point in the history
  • Loading branch information
esthel7 committed Dec 9, 2023
1 parent 720d84b commit e943355
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 0 additions & 2 deletions front/src/hooks/useLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import cookie from 'react-cookies';

const useLogout = () => {
window.open(`/api/auth/logout`, '_self');
cookie.remove('access_token');
cookie.remove('refresh_token');
cookie.remove('loggedin');
window.location.replace('/');
};
Expand Down
2 changes: 1 addition & 1 deletion front/src/pages/Intro/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Intro = () => {

useEffect(() => {
setMessageList(mockData.snowball_data.message_list as Array<Message>);
cookie.load('access_token') ? navigate('/main') : null;
cookie.load('loggedin') ? navigate('/main') : null;
}, [setMessageList, navigate]);

return (
Expand Down
7 changes: 7 additions & 0 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useRef, useContext, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import cookie from 'react-cookies';
import styled from 'styled-components';
import { Loading } from '@utils';
import { useLogout } from '@hooks';
Expand Down Expand Up @@ -104,6 +105,12 @@ const Main = () => {

useEffect(() => {
// saveCookie();

if (!cookie.load('loggedin')) {
navigate('/');
return;
}

axios
.get('/api/user', {
withCredentials: true // axios 쿠키 값 전달
Expand Down

0 comments on commit e943355

Please sign in to comment.