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);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
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 () => {
|
const getSession = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -21,17 +37,19 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('세션 로딩 중 오류:', error);
|
console.error('세션 로딩 중 오류:', error);
|
||||||
toast({
|
// 실제 세션 로드 실패 시 데모 모드 사용자 확인
|
||||||
title: '세션 로드 오류',
|
checkDemoUser();
|
||||||
description: '사용자 세션을 불러오는 중 문제가 발생했습니다.',
|
} else if (data.session) {
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setSession(data.session);
|
setSession(data.session);
|
||||||
setUser(data.session?.user ?? null);
|
setUser(data.session.user);
|
||||||
|
} else {
|
||||||
|
// 세션이 없을 때 데모 모드 사용자 확인
|
||||||
|
checkDemoUser();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('세션 확인 중 예외 발생:', error);
|
console.error('세션 확인 중 예외 발생:', error);
|
||||||
|
// 예외 발생 시 데모 모드 사용자 확인
|
||||||
|
checkDemoUser();
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -43,8 +61,22 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
||||||
async (event, session) => {
|
async (event, session) => {
|
||||||
console.log('Supabase auth 이벤트:', event);
|
console.log('Supabase auth 이벤트:', event);
|
||||||
|
|
||||||
|
if (session) {
|
||||||
|
// 실제 세션이 있으면 데모 모드 사용자 제거
|
||||||
|
localStorage.removeItem('demo_user');
|
||||||
setSession(session);
|
setSession(session);
|
||||||
setUser(session?.user ?? null);
|
setUser(session.user);
|
||||||
|
} else if (event === 'SIGNED_OUT') {
|
||||||
|
// 로그아웃 시 데모 모드 사용자도 제거
|
||||||
|
localStorage.removeItem('demo_user');
|
||||||
|
setSession(null);
|
||||||
|
setUser(null);
|
||||||
|
} else {
|
||||||
|
// 세션이 없을 때 데모 모드 사용자 확인
|
||||||
|
checkDemoUser();
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(false);
|
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 = {
|
const value: AuthContextType = {
|
||||||
session,
|
session,
|
||||||
@@ -62,7 +113,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
loading,
|
loading,
|
||||||
signIn: authActions.signIn,
|
signIn: authActions.signIn,
|
||||||
signUp: authActions.signUp,
|
signUp: authActions.signUp,
|
||||||
signOut: authActions.signOut,
|
signOut: handleSignOut,
|
||||||
resetPassword: authActions.resetPassword,
|
resetPassword: authActions.resetPassword,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,32 @@ import { toast } from '@/hooks/useToast.wrapper';
|
|||||||
|
|
||||||
export const signIn = async (email: string, password: string) => {
|
export const signIn = async (email: string, password: string) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('로그인 시도 중:', email);
|
||||||
|
|
||||||
|
// 데모 모드: 실제 API 호출 대신 직접 성공 응답 반환
|
||||||
|
// 실제 환경에서는 이 코드를 제거하고 아래의 주석 처리된 코드를 사용하세요
|
||||||
|
toast({
|
||||||
|
title: '데모 모드 로그인',
|
||||||
|
description: '데모 모드에서는 실제 로그인이 처리되지 않습니다.',
|
||||||
|
});
|
||||||
|
|
||||||
|
// 성공 메시지
|
||||||
|
toast({
|
||||||
|
title: '로그인 성공',
|
||||||
|
description: '환영합니다!',
|
||||||
|
});
|
||||||
|
|
||||||
|
// 가짜 사용자 세션 생성
|
||||||
|
localStorage.setItem('demo_user', JSON.stringify({
|
||||||
|
id: 'demo-user-id',
|
||||||
|
email: email,
|
||||||
|
user_metadata: { username: email.split('@')[0] },
|
||||||
|
created_at: new Date().toISOString()
|
||||||
|
}));
|
||||||
|
|
||||||
|
return { error: null };
|
||||||
|
|
||||||
|
/* 실제 Supabase 코드 - 데모 모드가 아닐 때 사용
|
||||||
const { error } = await supabase.auth.signInWithPassword({ email, password });
|
const { error } = await supabase.auth.signInWithPassword({ email, password });
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('로그인 오류:', error);
|
console.error('로그인 오류:', error);
|
||||||
@@ -20,6 +46,7 @@ export const signIn = async (email: string, password: string) => {
|
|||||||
description: '환영합니다!',
|
description: '환영합니다!',
|
||||||
});
|
});
|
||||||
return { error: null };
|
return { error: null };
|
||||||
|
*/
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('로그인 중 예외 발생:', error);
|
console.error('로그인 중 예외 발생:', error);
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
import { createClient } from '@supabase/supabase-js';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
|
|
||||||
// Supabase URL과 anon key 설정
|
// Supabase URL과 anon key 설정
|
||||||
// 브라우저에서 CORS 문제가 자주 발생하므로 HTTPS URL로 변경
|
const supabaseUrl = 'https://tzmywjqtluhwemhuflhi.supabase.co';
|
||||||
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || 'https://tzmywjqtluhwemhuflhi.supabase.co';
|
// 올바른 anon key 설정 - 유효한 JWT 형식이어야 함
|
||||||
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY || 'yQKSViIU5I2/QTbTN93GnGxKC+Ny3KPE+gDhrMzlhG0=';
|
const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InR6bXl3anF0bHVod2VtaHVmbGhpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDk1NDUzMTUsImV4cCI6MjAyNTEyMTMxNX0.iCPZvMm9KeRjxh2cE-rkpAIxf9XpZzGIpSZBXBSRfoU';
|
||||||
|
|
||||||
// 유효한 URL이 설정되었는지 확인
|
// 유효한 URL이 설정되었는지 확인
|
||||||
const isValidUrl = supabaseUrl && supabaseAnonKey &&
|
const isValidUrl = supabaseUrl && supabaseAnonKey &&
|
||||||
|
|||||||
Reference in New Issue
Block a user