Debug login issues in lovable app

Investigate and address potential causes of login failures in the lovable app, including API request format discrepancies, cached token issues, and network problems.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 15:36:57 +00:00
parent 03fcc7175c
commit 0f4f426dd4
5 changed files with 91 additions and 61 deletions

View File

@@ -23,30 +23,26 @@ export const signIn = async (email: string, password: string) => {
console.log('로그인 시도 중:', email);
// Supabase 기본 인증 시도
// 직접 API 호출 방식 시도
try {
const { data, error } = await supabase.auth.signInWithPassword({
email,
password
});
return await signInWithDirectApi(email, password);
} catch (directApiError: any) {
console.error('직접 API 호출 방식 실패:', directApiError);
if (!error && data.user) {
showAuthToast('로그인 성공', '환영합니다!');
return { error: null, user: data.user };
} else if (error) {
console.error('로그인 오류:', error.message);
// 기본 Supabase 인증 방식 시도
try {
const { data, error } = await supabase.auth.signInWithPassword({
email,
password
});
// REST API 오류인 경우 직접 API 호출 시도
if (error.message.includes('json') ||
error.message.includes('Unexpected end') ||
error.message.includes('404') ||
error.message.includes('Not Found')) {
console.warn('기본 로그인 실패, 직접 API 호출 시도:', error.message);
return await signInWithDirectApi(email, password);
} else {
// 다른 종류의 오류는 그대로 반환
let errorMessage = error.message;
if (!error && data.user) {
showAuthToast('로그인 성공', '환영합니다!');
return { error: null, user: data.user };
} else if (error) {
console.error('Supabase 기본 로그인 오류:', error.message);
let errorMessage = error.message;
if (error.message.includes('Invalid login credentials')) {
errorMessage = '이메일 또는 비밀번호가 올바르지 않습니다.';
} else if (error.message.includes('Email not confirmed')) {
@@ -56,24 +52,17 @@ export const signIn = async (email: string, password: string) => {
showAuthToast('로그인 실패', errorMessage, 'destructive');
return { error: { message: errorMessage }, user: null };
}
} catch (basicAuthError: any) {
console.warn('Supabase 기본 인증 방식 예외 발생:', basicAuthError);
// 오류 전파
throw directApiError;
}
} catch (basicAuthError: any) {
console.warn('기본 인증 방식 예외 발생:', basicAuthError);
// 404 에러나 경로 오류인 경우에도 직접 API 호출 시도
if (basicAuthError.message && (
basicAuthError.message.includes('404') ||
basicAuthError.message.includes('Not Found')
)) {
return await signInWithDirectApi(email, password);
}
// 기본 로그인 실패 시 아래 직접 API 호출 방식 계속 진행
return await signInWithDirectApi(email, password);
}
// 기본 방식이 성공적으로 완료되지 않았을 경우 직접 API 호출
return await signInWithDirectApi(email, password);
// 여기까지 왔다면 모든 로그인 시도가 실패한 것
showAuthToast('로그인 실패', '로그인 처리 중 오류가 발생했습니다.', 'destructive');
return { error: { message: '로그인 처리 중 오류가 발생했습니다.' }, user: null };
} catch (error: any) {
console.error('로그인 중 예외 발생:', error);