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:
@@ -9,19 +9,19 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
console.log('직접 API 호출로 로그인 시도');
|
||||
|
||||
try {
|
||||
// 로그인 API 엔드포인트 URL 준비
|
||||
const supabaseUrl = localStorage.getItem('supabase_url') || 'http://a11.ism.kr';
|
||||
// API 호출 URL 및 헤더 설정
|
||||
const supabaseUrl = localStorage.getItem('supabase_url') || 'https://a11.ism.kr';
|
||||
const supabaseKey = localStorage.getItem('supabase_key') || supabase.supabaseKey;
|
||||
|
||||
// URL에 auth/v1이 이미 포함되어있는지 확인
|
||||
const baseUrl = supabaseUrl.includes('/auth/v1') ? supabaseUrl : `${supabaseUrl}/auth/v1`;
|
||||
|
||||
// 토큰 엔드포인트 경로
|
||||
// 토큰 엔드포인트 경로 (curl 테스트와 동일한 형식으로)
|
||||
const tokenUrl = `${baseUrl}/token?grant_type=password`;
|
||||
|
||||
console.log('로그인 API 요청 URL:', tokenUrl);
|
||||
|
||||
// 로그인 요청 보내기
|
||||
// 로그인 요청 보내기 (curl 테스트와 동일한 형식으로)
|
||||
const response = await fetch(tokenUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -36,6 +36,7 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
|
||||
// HTTP 상태 코드 확인
|
||||
if (response.status === 401) {
|
||||
console.log('로그인 실패: 인증 오류');
|
||||
showAuthToast('로그인 실패', '이메일 또는 비밀번호가 올바르지 않습니다.', 'destructive');
|
||||
return {
|
||||
error: { message: '인증 실패: 이메일 또는 비밀번호가 올바르지 않습니다.' },
|
||||
@@ -98,24 +99,20 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
}
|
||||
|
||||
// 응답 처리
|
||||
const responseData = await parseResponse(response);
|
||||
const responseText = await response.text();
|
||||
console.log('로그인 응답 내용:', responseText);
|
||||
|
||||
// 빈 응답이나 파싱 실패 시
|
||||
if (responseData.status && !responseData.success && !responseData.error) {
|
||||
let responseData;
|
||||
try {
|
||||
// 응답이 비어있지 않은 경우에만 JSON 파싱 시도
|
||||
responseData = responseText ? JSON.parse(responseText) : {};
|
||||
} catch (e) {
|
||||
console.warn('JSON 파싱 실패:', e, '원본 응답:', responseText);
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
// 성공 상태 코드이지만 응답 내용 없음
|
||||
showAuthToast('로그인 상태 확인 필요', '서버가 성공 응답을 보냈지만 내용이 없습니다. 세션 상태를 확인하세요.');
|
||||
|
||||
// 사용자 세션 확인 시도
|
||||
try {
|
||||
const { data: userData } = await supabase.auth.getUser();
|
||||
if (userData.user) {
|
||||
showAuthToast('로그인 성공', '환영합니다!');
|
||||
return { error: null, user: userData.user };
|
||||
}
|
||||
} catch (sessionCheckError) {
|
||||
console.error('세션 확인 오류:', sessionCheckError);
|
||||
}
|
||||
// 성공 응답이지만 JSON이 아닌 경우 (빈 응답 등)
|
||||
responseData = { success: true };
|
||||
} else {
|
||||
responseData = { error: '서버 응답을 처리할 수 없습니다' };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +145,24 @@ export const signInWithDirectApi = async (email: string, password: string) => {
|
||||
showAuthToast('로그인 후처리 오류', '로그인에 성공했지만 세션 설정에 실패했습니다.', 'destructive');
|
||||
return { error: { message: '세션 설정 오류' }, user: null };
|
||||
}
|
||||
} else if (response.ok) {
|
||||
// 응답 내용 없이 성공 상태인 경우
|
||||
try {
|
||||
// 사용자 세션 확인 시도
|
||||
const { data: userData } = await supabase.auth.getUser();
|
||||
if (userData.user) {
|
||||
showAuthToast('로그인 성공', '환영합니다!');
|
||||
return { error: null, user: userData.user };
|
||||
} else {
|
||||
// 세션은 있지만 사용자 정보가 없는 경우
|
||||
showAuthToast('로그인 부분 성공', '로그인은 성공했지만 사용자 정보를 가져오지 못했습니다.', 'default');
|
||||
return { error: { message: '사용자 정보 조회 실패' }, user: null };
|
||||
}
|
||||
} catch (userError) {
|
||||
console.error('사용자 정보 조회 오류:', userError);
|
||||
showAuthToast('로그인 후처리 오류', '로그인은 성공했지만 사용자 정보를 가져오지 못했습니다.', 'destructive');
|
||||
return { error: { message: '사용자 정보 조회 실패' }, user: null };
|
||||
}
|
||||
} else {
|
||||
// 오류 응답이나 예상치 못한 응답 형식 처리
|
||||
console.error('로그인 오류 응답:', responseData);
|
||||
|
||||
Reference in New Issue
Block a user