Files
zellyy-finance/src/contexts/auth/authActions.ts
gpt-engineer-app[bot] fd34c62170 Refactor AuthContext into smaller files
Refactors the AuthContext.tsx file into smaller, more manageable files to improve code organization and maintainability. The functionality remains the same.
2025-03-15 06:57:27 +00:00

135 lines
3.5 KiB
TypeScript

import { supabase } from '@/lib/supabase';
import { toast } from '@/hooks/useToast.wrapper';
export const signIn = async (email: string, password: string) => {
try {
const { error } = await supabase.auth.signInWithPassword({ email, password });
if (error) {
console.error('로그인 오류:', error);
toast({
title: '로그인 실패',
description: error.message,
variant: 'destructive',
});
return { error };
}
toast({
title: '로그인 성공',
description: '환영합니다!',
});
return { error: null };
} catch (error: any) {
console.error('로그인 중 예외 발생:', error);
toast({
title: '로그인 오류',
description: '예상치 못한 오류가 발생했습니다.',
variant: 'destructive',
});
return { error };
}
};
export const signUp = async (email: string, password: string, username: string) => {
try {
// Supabase 인증으로 사용자 생성
const { data, error } = await supabase.auth.signUp({
email,
password,
options: {
data: {
username,
},
},
});
if (error) {
console.error('회원가입 오류:', error);
toast({
title: '회원가입 실패',
description: error.message,
variant: 'destructive',
});
return { error, user: null };
}
toast({
title: '회원가입 성공',
description: '이메일 확인 후 로그인해주세요.',
});
return { error: null, user: data.user };
} catch (error: any) {
console.error('회원가입 중 예외 발생:', error);
toast({
title: '회원가입 오류',
description: '예상치 못한 오류가 발생했습니다.',
variant: 'destructive',
});
return { error, user: null };
}
};
export const signOut = async () => {
try {
const { error } = await supabase.auth.signOut();
if (error) {
console.error('로그아웃 오류:', error);
toast({
title: '로그아웃 실패',
description: error.message,
variant: 'destructive',
});
return { error };
}
toast({
title: '로그아웃 성공',
description: '다음에 또 만나요!',
});
return { error: null };
} catch (error: any) {
console.error('로그아웃 중 예외 발생:', error);
toast({
title: '로그아웃 오류',
description: '예상치 못한 오류가 발생했습니다.',
variant: 'destructive',
});
return { error };
}
};
export const resetPassword = async (email: string) => {
try {
const { error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: window.location.origin + '/reset-password',
});
if (error) {
console.error('비밀번호 재설정 오류:', error);
toast({
title: '비밀번호 재설정 실패',
description: error.message,
variant: 'destructive',
});
return { error };
}
toast({
title: '비밀번호 재설정 이메일 전송됨',
description: '이메일을 확인하여 비밀번호를 재설정해주세요.',
});
return { error: null };
} catch (error: any) {
console.error('비밀번호 재설정 중 예외 발생:', error);
toast({
title: '비밀번호 재설정 오류',
description: '예상치 못한 오류가 발생했습니다.',
variant: 'destructive',
});
return { error };
}
};