diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index fec0aa2c..d3cb3048 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -36,6 +36,7 @@ const Header = () => { Cookies.remove('accessToken'); Cookies.remove('refreshToken'); + await profileContext?.refetchProfile(); router.push('/'); } catch (error) { alert('로그아웃에 실패하였습니다.\n다시 시도해주세요'); diff --git a/src/components/providers/ProfileProvider.tsx b/src/components/providers/ProfileProvider.tsx index 5e694814..4ffec413 100644 --- a/src/components/providers/ProfileProvider.tsx +++ b/src/components/providers/ProfileProvider.tsx @@ -47,6 +47,10 @@ const ProfileProvider = ({ children }: ProfileProviderProps) => { } }, [profileQuery.data]); + const refetchProfile = async () => { + await profileQuery.refetch(); + }; + return ( { setProfile, status: profileQuery.status, isInitialLoading: profileQuery.isInitialLoading, + refetchProfile, }} > {children} diff --git a/src/contexts/ProfileContext.tsx b/src/contexts/ProfileContext.tsx index aa85ea05..8de151af 100644 --- a/src/contexts/ProfileContext.tsx +++ b/src/contexts/ProfileContext.tsx @@ -7,6 +7,7 @@ interface ProfileState { setProfile: React.Dispatch>; status: 'loading' | 'error' | 'success'; isInitialLoading: boolean; + refetchProfile: () => Promise; } const ProfileContext = createContext(null);