Skip to content

Commit

Permalink
Fix : 새로고침 났을 때도 핸들링 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
YoommY2 committed Aug 15, 2022
1 parent 1b2ddab commit 5b14d24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import SurveyPage from './pages/SurveyPage';
import SurveyIntroPage from './pages/SurveyIntroPage';
import BrandDetailPage from './pages/BrandDetailPage';
import NotFoundPage from './pages/NotFoundPage';
import { KakaoRefresh } from './components/SharedComponents/RefreshToken';
import axios from 'axios';
import { useRecoilState } from 'recoil';
import { loginState } from './recoil';

function App() {

const KakaoRefresh = async () => {
const [loggedin, setLoggedIn] = useRecoilState(loginState);
try {
const response = await axios.post(
'https://api.found-er.co.kr/api/token/refresh',
Expand All @@ -29,13 +25,13 @@ function App() {

localStorage.setItem('accesstoken', response.data.access);
localStorage.setItem('refreshtoken', response.data.refresh);
setLoggedIn(true);
setTimeout(KakaoRefresh, 1000 * 60 * 4);
} catch (e) {
console.log(e);
console.log('리프레쉬 불가');
}

setInterval(KakaoRefresh, 1000 * 60 * 4);

};
// checkAccessToken(localStorage.refreshtoken);

Expand All @@ -51,11 +47,12 @@ function App() {
}
);*/

/*window.addEventListener('unload', (event) => {
event.preventDefault();
KakaoRefresh();
event.returnValue = '';
});*/
if (performance.navigation.type===1){
//새로고침하면 바로 로그인 연장(토큰 갱신)
if(localStorage.accesstoken)
KakaoRefresh();
}

return (
<>
<Routes>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const MyPage = () => {
console.log('로그아웃 실패');
});
}

useEffect(() => {
fetchUserInfo({ setuserData, access });
}, [access]);
Expand Down

0 comments on commit 5b14d24

Please sign in to comment.