From 618d1e10580384bd415b7268a659db00fbcfb892 Mon Sep 17 00:00:00 2001 From: seung365 Date: Wed, 7 Aug 2024 18:47:39 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A0=8C=EB=8D=94=EB=A7=81=EC=8B=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=83=81=ED=83=9C=20=EC=9C=A0?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Provider/Auth.tsx | 22 ++++++++++++++++++++-- src/pages/Login/AuthPage.tsx | 5 ++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Provider/Auth.tsx b/src/Provider/Auth.tsx index 8a0c92f..cbe3b3d 100644 --- a/src/Provider/Auth.tsx +++ b/src/Provider/Auth.tsx @@ -1,5 +1,5 @@ import { AuthContextType, AuthInfo } from '@/types'; -import { createContext, useContext, useState, ReactNode } from 'react'; +import { createContext, useContext, useState, ReactNode, useEffect } from 'react'; export const AuthContext = createContext(undefined); @@ -9,10 +9,28 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { const updateAuthInfo = (auth: AuthInfo) => { if (auth) { setAuthInfo(auth); - sessionStorage.setItem('authToken', auth.accessToken); } }; + const handleAuthInfo = () => { + const authToken = sessionStorage.getItem('authToken'); + if (authToken) { + const email = sessionStorage.getItem('email') || ''; + const name = sessionStorage.getItem('name') || ''; + const picture = sessionStorage.getItem('picture') || ''; + setAuthInfo({ + accessToken: authToken, + email: email, + name: name, + picture: picture, + }); + } + }; + + useEffect(() => { + handleAuthInfo(); + }); + return ( {children} ); diff --git a/src/pages/Login/AuthPage.tsx b/src/pages/Login/AuthPage.tsx index 312c65c..ecc4f93 100644 --- a/src/pages/Login/AuthPage.tsx +++ b/src/pages/Login/AuthPage.tsx @@ -24,7 +24,10 @@ export const AuthPage = () => { name: data.name, email: data.email, }); - + sessionStorage.setItem('authToken', data.accessToken); + sessionStorage.setItem('name', data.name); + sessionStorage.setItem('picture', data.picture); + sessionStorage.setItem('email', data.email); navigate(RouterPath.home); } else if (error) { console.error('Login failed:', error);