From 8685e4447c0985b0bf56f65ce3fae0f4924945bd Mon Sep 17 00:00:00 2001 From: lydiacho Date: Thu, 31 Oct 2024 13:28:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20clearStorage=20=EC=9C=A0=ED=8B=B8?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/storage.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 74be6860..78b079a2 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -13,3 +13,8 @@ export const setRole = (role: string) => { export const getRole = () => { return localStorage.getItem('seonyakRole'); }; + +export const clearStorage = () => { + localStorage.removeItem('seonyakToken'); + localStorage.removeItem('seonyakRole'); +}; From fc10427f66024ebdd3be43774bd1f5fb10dd46e0 Mon Sep 17 00:00:00 2001 From: lydiacho Date: Thu, 31 Oct 2024 13:45:16 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20?= =?UTF-8?q?=EC=9D=B4=ED=83=88=20=ED=9B=84=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=ED=95=98=EB=8A=94=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?=EC=9C=A0=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login/hooks/useGoogleLoginMutation.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/login/hooks/useGoogleLoginMutation.ts b/src/pages/login/hooks/useGoogleLoginMutation.ts index ec92914d..e11b8699 100644 --- a/src/pages/login/hooks/useGoogleLoginMutation.ts +++ b/src/pages/login/hooks/useGoogleLoginMutation.ts @@ -1,7 +1,7 @@ import { useMutation } from '@tanstack/react-query'; import { loginAxios } from '../apis/loginAxios'; import { useNavigate } from 'react-router-dom'; -import { setRole, setToken } from '@utils/storage'; +import { clearStorage, setRole, setToken } from '@utils/storage'; interface useGoogleLoginPropType { role?: string; @@ -22,8 +22,11 @@ const useGoogleLoginMutation = ({ role }: useGoogleLoginPropType) => { // 회원가입 navigate(role === 'SENIOR' ? '/seniorOnboarding' : '/juniorOnboarding'); } else { - // 로그인인데, role 정보를 서버에서 받지 못한 상황 - console.error('🔴 로그인 과정에서 Role 정보를 서버에서 받지 못했어요.'); + // 존재하지 않는 계정으로 로그인을 시도했을 경우 + console.error('🔴 존재하지 않는 계정'); + alert('존재하지 않는 계정이예요. 회원가입을 진행해주세요.'); + navigate('/'); + clearStorage(); } }, onError: (error) => { From e7d17178ee79710ca8b63e124381302448c875a9 Mon Sep 17 00:00:00 2001 From: lydiacho Date: Thu, 31 Oct 2024 13:59:03 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=20=EC=9E=AC=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9C=A0=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/apis/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils/apis/index.ts b/src/utils/apis/index.ts index 35862b49..b7ddfa7e 100644 --- a/src/utils/apis/index.ts +++ b/src/utils/apis/index.ts @@ -1,4 +1,4 @@ -import { getToken } from '@utils/storage'; +import { clearStorage, getToken } from '@utils/storage'; import * as _axios from 'axios'; const baseUrl = import.meta.env.VITE_APP_API_BASE_URL; @@ -29,3 +29,15 @@ authAxios.interceptors.request.use( return Promise.reject(error); } ); + +authAxios.interceptors.response.use( + (res) => res, + async (err) => { + if (err.response.data.code === '40076') { + alert(`세션이 만료되었습니다.\n다시 로그인해주세요.`); + clearStorage(); + location.href = '/'; + } + return Promise.reject(err); + } +);