Fix sign-up failure handling
The sign-up failure logic was not properly implemented. This commit addresses the issue.
This commit is contained in:
@@ -22,9 +22,15 @@ export const signIn = async (email: string, password: string) => {
|
||||
return { error: null };
|
||||
} catch (error: any) {
|
||||
console.error('로그인 중 예외 발생:', error);
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = error.message && error.message.includes('fetch')
|
||||
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
|
||||
: '예상치 못한 오류가 발생했습니다.';
|
||||
|
||||
toast({
|
||||
title: '로그인 오류',
|
||||
description: '예상치 못한 오류가 발생했습니다.',
|
||||
description: errorMessage,
|
||||
variant: 'destructive',
|
||||
});
|
||||
return { error };
|
||||
@@ -33,6 +39,20 @@ export const signIn = async (email: string, password: string) => {
|
||||
|
||||
export const signUp = async (email: string, password: string, username: string) => {
|
||||
try {
|
||||
// 먼저 서버 연결 테스트
|
||||
try {
|
||||
const { data: sessionData } = await supabase.auth.getSession();
|
||||
console.log('Supabase 서버 연결 확인:', sessionData ? '성공' : '응답 받음');
|
||||
} catch (connError: any) {
|
||||
console.error('Supabase 연결 테스트 실패:', connError);
|
||||
toast({
|
||||
title: '서버 연결 오류',
|
||||
description: '인증 서버에 연결할 수 없습니다. 네트워크 연결을 확인해주세요.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return { error: connError, user: null };
|
||||
}
|
||||
|
||||
// Supabase 인증으로 사용자 생성
|
||||
const { data, error } = await supabase.auth.signUp({
|
||||
email,
|
||||
@@ -62,9 +82,15 @@ export const signUp = async (email: string, password: string, username: string)
|
||||
return { error: null, user: data.user };
|
||||
} catch (error: any) {
|
||||
console.error('회원가입 중 예외 발생:', error);
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = error.message && error.message.includes('fetch')
|
||||
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
|
||||
: '예상치 못한 오류가 발생했습니다.';
|
||||
|
||||
toast({
|
||||
title: '회원가입 오류',
|
||||
description: '예상치 못한 오류가 발생했습니다.',
|
||||
description: errorMessage,
|
||||
variant: 'destructive',
|
||||
});
|
||||
return { error, user: null };
|
||||
@@ -90,9 +116,15 @@ export const signOut = async (): Promise<void> => {
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('로그아웃 중 예외 발생:', error);
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = error.message && error.message.includes('fetch')
|
||||
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
|
||||
: '예상치 못한 오류가 발생했습니다.';
|
||||
|
||||
toast({
|
||||
title: '로그아웃 오류',
|
||||
description: '예상치 못한 오류가 발생했습니다.',
|
||||
description: errorMessage,
|
||||
variant: 'destructive',
|
||||
});
|
||||
}
|
||||
@@ -121,9 +153,15 @@ export const resetPassword = async (email: string) => {
|
||||
return { error: null };
|
||||
} catch (error: any) {
|
||||
console.error('비밀번호 재설정 중 예외 발생:', error);
|
||||
|
||||
// 네트워크 오류 확인
|
||||
const errorMessage = error.message && error.message.includes('fetch')
|
||||
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
|
||||
: '예상치 못한 오류가 발생했습니다.';
|
||||
|
||||
toast({
|
||||
title: '비밀번호 재설정 오류',
|
||||
description: '예상치 못한 오류가 발생했습니다.',
|
||||
description: errorMessage,
|
||||
variant: 'destructive',
|
||||
});
|
||||
return { error };
|
||||
|
||||
@@ -14,6 +14,24 @@ const isValidUrl = supabaseUrl && supabaseAnonKey &&
|
||||
let supabaseClient;
|
||||
|
||||
try {
|
||||
console.log(`Supabase 클라이언트 생성 시도: ${supabaseUrl}`);
|
||||
|
||||
// 테스트용 fetch 실행
|
||||
try {
|
||||
fetch(`${supabaseUrl}/auth/v1/signup`, {
|
||||
method: 'OPTIONS',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(response => {
|
||||
console.log(`Supabase 서버 연결 테스트 응답:`, response.status);
|
||||
}).catch(err => {
|
||||
console.warn(`Supabase 서버 연결 테스트 실패:`, err.message);
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn('Supabase 서버 연결 테스트 중 오류:', e);
|
||||
}
|
||||
|
||||
// Supabase 클라이언트 생성
|
||||
supabaseClient = createClient(supabaseUrl, supabaseAnonKey, {
|
||||
auth: {
|
||||
@@ -36,8 +54,11 @@ try {
|
||||
supabaseClient = {
|
||||
auth: {
|
||||
getUser: () => Promise.resolve({ data: { user: null } }),
|
||||
getSession: () => Promise.resolve({ data: { session: null } }),
|
||||
signInWithPassword: () => Promise.reject(new Error('Supabase 설정이 필요합니다')),
|
||||
signUp: () => Promise.reject(new Error('Supabase 설정이 필요합니다')),
|
||||
signOut: () => Promise.resolve({ error: null }),
|
||||
onAuthStateChange: () => ({ data: { subscription: { unsubscribe: () => {} } } }),
|
||||
},
|
||||
from: () => ({
|
||||
select: () => ({ eq: () => ({ data: null, error: new Error('Supabase 설정이 필요합니다') }) }),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@@ -52,8 +53,17 @@ const Register = () => {
|
||||
const { error, user } = await signUp(email, password, username);
|
||||
|
||||
if (!error && user) {
|
||||
toast({
|
||||
title: "회원가입 완료",
|
||||
description: "로그인 페이지로 이동합니다.",
|
||||
});
|
||||
navigate("/login");
|
||||
} else if (error) {
|
||||
// 에러는 이미 signUp 함수 내에서 처리되므로 추가 처리 필요 없음
|
||||
console.log("회원가입 중 오류 발생:", error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("회원가입 처리 중 예외 발생:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user