Update login failure message
Update the message displayed upon login failure.
This commit is contained in:
@@ -14,6 +14,22 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// 데모 모드 사용자 체크
|
||||
const checkDemoUser = () => {
|
||||
const demoUser = localStorage.getItem('demo_user');
|
||||
if (demoUser) {
|
||||
try {
|
||||
const parsedUser = JSON.parse(demoUser) as User;
|
||||
setUser(parsedUser);
|
||||
// 데모 모드에서는 session이 null이지만 user는 있을 수 있음
|
||||
setSession(null);
|
||||
} catch (error) {
|
||||
console.error('데모 사용자 파싱 오류:', error);
|
||||
localStorage.removeItem('demo_user');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 현재 세션 체크
|
||||
const getSession = async () => {
|
||||
try {
|
||||
@@ -21,17 +37,19 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
|
||||
if (error) {
|
||||
console.error('세션 로딩 중 오류:', error);
|
||||
toast({
|
||||
title: '세션 로드 오류',
|
||||
description: '사용자 세션을 불러오는 중 문제가 발생했습니다.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} else {
|
||||
// 실제 세션 로드 실패 시 데모 모드 사용자 확인
|
||||
checkDemoUser();
|
||||
} else if (data.session) {
|
||||
setSession(data.session);
|
||||
setUser(data.session?.user ?? null);
|
||||
setUser(data.session.user);
|
||||
} else {
|
||||
// 세션이 없을 때 데모 모드 사용자 확인
|
||||
checkDemoUser();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('세션 확인 중 예외 발생:', error);
|
||||
// 예외 발생 시 데모 모드 사용자 확인
|
||||
checkDemoUser();
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -43,8 +61,22 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
||||
async (event, session) => {
|
||||
console.log('Supabase auth 이벤트:', event);
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
if (session) {
|
||||
// 실제 세션이 있으면 데모 모드 사용자 제거
|
||||
localStorage.removeItem('demo_user');
|
||||
setSession(session);
|
||||
setUser(session.user);
|
||||
} else if (event === 'SIGNED_OUT') {
|
||||
// 로그아웃 시 데모 모드 사용자도 제거
|
||||
localStorage.removeItem('demo_user');
|
||||
setSession(null);
|
||||
setUser(null);
|
||||
} else {
|
||||
// 세션이 없을 때 데모 모드 사용자 확인
|
||||
checkDemoUser();
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
);
|
||||
@@ -55,6 +87,25 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
};
|
||||
}, []);
|
||||
|
||||
// signOut 메소드 재정의 - 데모 모드 지원
|
||||
const handleSignOut = async () => {
|
||||
// 데모 모드 사용자 체크
|
||||
const demoUser = localStorage.getItem('demo_user');
|
||||
if (demoUser) {
|
||||
localStorage.removeItem('demo_user');
|
||||
setUser(null);
|
||||
setSession(null);
|
||||
toast({
|
||||
title: '로그아웃 성공',
|
||||
description: '다음에 또 만나요!',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 실제 Supabase 로그아웃
|
||||
await authActions.signOut();
|
||||
};
|
||||
|
||||
// 인증 작업 메서드들
|
||||
const value: AuthContextType = {
|
||||
session,
|
||||
@@ -62,7 +113,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
loading,
|
||||
signIn: authActions.signIn,
|
||||
signUp: authActions.signUp,
|
||||
signOut: authActions.signOut,
|
||||
signOut: handleSignOut,
|
||||
resetPassword: authActions.resetPassword,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user