diff --git a/src/contexts/auth/authActions.ts b/src/contexts/auth/authActions.ts index b27d076..3405e58 100644 --- a/src/contexts/auth/authActions.ts +++ b/src/contexts/auth/authActions.ts @@ -41,7 +41,8 @@ export const signIn = async (email: string, password: string) => { return { error: { message: '서버 응답을 처리할 수 없습니다. CORS 프록시 설정을 확인하세요.' - } + }, + user: null }; } @@ -72,7 +73,7 @@ export const signIn = async (email: string, password: string) => { responseData?.error || '로그인에 실패했습니다. 이메일과 비밀번호를 확인하세요.'; - return { error: { message: errorMessage } }; + return { error: { message: errorMessage }, user: null }; } } catch (error: any) { console.error('로그인 중 예외 발생:', error); @@ -82,7 +83,7 @@ export const signIn = async (email: string, password: string) => { ? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.' : (error.message || '예상치 못한 오류가 발생했습니다.'); - return { error: { message: errorMessage } }; + return { error: { message: errorMessage }, user: null }; } }; diff --git a/src/contexts/auth/types.ts b/src/contexts/auth/types.ts index 6135f2f..647dddc 100644 --- a/src/contexts/auth/types.ts +++ b/src/contexts/auth/types.ts @@ -5,7 +5,7 @@ export type AuthContextType = { session: Session | null; user: User | null; loading: boolean; - signIn: (email: string, password: string) => Promise<{ error: any }>; + signIn: (email: string, password: string) => Promise<{ error: any; user?: any }>; signUp: (email: string, password: string, username: string) => Promise<{ error: any, user: any }>; signOut: () => Promise; resetPassword: (email: string) => Promise<{ error: any }>; diff --git a/src/hooks/useLogin.ts b/src/hooks/useLogin.ts index be4f22b..81efeee 100644 --- a/src/hooks/useLogin.ts +++ b/src/hooks/useLogin.ts @@ -62,7 +62,7 @@ export function useLogin() { description: errorMessage, variant: "destructive" }); - } else { + } else if (user) { // 로그인 성공 시 필요한 테이블 설정 try { setIsSettingUpTables(true); @@ -80,6 +80,15 @@ export function useLogin() { setIsSettingUpTables(false); } + navigate("/"); + } else { + // user가 없지만 error도 없는 경우 (드문 경우) + console.warn("로그인 성공했지만 사용자 정보가 없습니다."); + toast({ + title: "로그인 상태 확인 중", + description: "로그인은 성공했지만 사용자 정보를 확인하지 못했습니다. 페이지를 새로고침해보세요.", + variant: "default" + }); navigate("/"); } } catch (err: any) {