src / service / auth / signUp.ts
import { supabase } from "@/lib/supabaseClient";
import { signUpType } from "@/types/auth/signUp.type";
export async function signUp({ email, password }: signUpType) {
const { data, error } = await supabase.auth.signUp({ email, password });
return { data, error };
}
src / hooks / useAuth.ts
import { useModalStore } from "@/store";
import { useRouter } from "next/navigation";
import { signUpType } from "@/types/auth/signUp.type";
const useAuth = () => {
const { open } = useModalStore();
const router = useRouter();
// 회원가입
async function handleSignUp({ email, password }: signUpType) {
const { data, error } = await signUp({ email, password });
// 이메일 중복 검사
if (data?.user?.aud === "authenticated") {
open({
title: "Error",
content: `회원가입 에러 발생
이미 가입된 이메일입니다.
`,
});
}
// 에러 검사
else if (error) {
open({
title: "Error",
content: `회원가입 에러 발생
잠시 후 다시 시도해주세요.
`,
});
}
// 인증 메일 발송 완료 페이지로 리다이렉트
else {
router.push("/sign-up/email-sent");
}
}
return { handleSignUp };
};
export default useAuth;
'백엔드 > Supabase' 카테고리의 다른 글
[Supabase] Supabase 이미지 업로드 기능 사용방법 A to Z (0) | 2025.01.16 |
---|---|
[Supabase] Supabase 카카오톡 로그인 기능 사용방법 A to Z (0) | 2025.01.16 |
[Supabase] 로그인 기능 구현하기 (0) | 2024.12.18 |
[Supabase] 회원가입 인증 메일로 커스텀 리다이렉트 경로 설정하기 (1) | 2024.11.30 |