Fix TS2339 error in useLogin

The property 'user' might not exist on the returned object from signIn.
Handle the case where user is undefined.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 13:07:14 +00:00
parent a8537d5398
commit 8931ee4bb6
3 changed files with 15 additions and 5 deletions

View File

@@ -41,7 +41,8 @@ export const signIn = async (email: string, password: string) => {
return { return {
error: { error: {
message: '서버 응답을 처리할 수 없습니다. CORS 프록시 설정을 확인하세요.' message: '서버 응답을 처리할 수 없습니다. CORS 프록시 설정을 확인하세요.'
} },
user: null
}; };
} }
@@ -72,7 +73,7 @@ export const signIn = async (email: string, password: string) => {
responseData?.error || responseData?.error ||
'로그인에 실패했습니다. 이메일과 비밀번호를 확인하세요.'; '로그인에 실패했습니다. 이메일과 비밀번호를 확인하세요.';
return { error: { message: errorMessage } }; return { error: { message: errorMessage }, user: null };
} }
} catch (error: any) { } catch (error: any) {
console.error('로그인 중 예외 발생:', error); console.error('로그인 중 예외 발생:', error);
@@ -82,7 +83,7 @@ export const signIn = async (email: string, password: string) => {
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.' ? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
: (error.message || '예상치 못한 오류가 발생했습니다.'); : (error.message || '예상치 못한 오류가 발생했습니다.');
return { error: { message: errorMessage } }; return { error: { message: errorMessage }, user: null };
} }
}; };

View File

@@ -5,7 +5,7 @@ export type AuthContextType = {
session: Session | null; session: Session | null;
user: User | null; user: User | null;
loading: boolean; 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 }>; signUp: (email: string, password: string, username: string) => Promise<{ error: any, user: any }>;
signOut: () => Promise<void>; signOut: () => Promise<void>;
resetPassword: (email: string) => Promise<{ error: any }>; resetPassword: (email: string) => Promise<{ error: any }>;

View File

@@ -62,7 +62,7 @@ export function useLogin() {
description: errorMessage, description: errorMessage,
variant: "destructive" variant: "destructive"
}); });
} else { } else if (user) {
// 로그인 성공 시 필요한 테이블 설정 // 로그인 성공 시 필요한 테이블 설정
try { try {
setIsSettingUpTables(true); setIsSettingUpTables(true);
@@ -80,6 +80,15 @@ export function useLogin() {
setIsSettingUpTables(false); setIsSettingUpTables(false);
} }
navigate("/");
} else {
// user가 없지만 error도 없는 경우 (드문 경우)
console.warn("로그인 성공했지만 사용자 정보가 없습니다.");
toast({
title: "로그인 상태 확인 중",
description: "로그인은 성공했지만 사용자 정보를 확인하지 못했습니다. 페이지를 새로고침해보세요.",
variant: "default"
});
navigate("/"); navigate("/");
} }
} catch (err: any) { } catch (err: any) {