diff --git a/web/lib/util/signup.ts b/web/lib/util/signup.ts index cb0ce07a..18105f7d 100644 --- a/web/lib/util/signup.ts +++ b/web/lib/util/signup.ts @@ -5,13 +5,12 @@ import { getLoverRow } from 'common/love/lover' export const signupThenMaybeRedirectToSignup = async () => { const creds = await firebaseLogin() + await Router.push('/') const userId = creds?.user.uid if (userId) { const lover = await getLoverRow(userId, db) if (!lover) { await Router.push('/signup') - } else { - await Router.push('/') } } } diff --git a/web/pages/register.tsx b/web/pages/register.tsx index 974e3075..3b1b7924 100644 --- a/web/pages/register.tsx +++ b/web/pages/register.tsx @@ -14,24 +14,6 @@ import {getLoverRow} from "common/love/lover"; import {db} from "web/lib/supabase/db"; import Router from "next/router"; -const handleEmailPasswordSignUp = async (email: string, password: string) => { - try { - const creds = await createUserWithEmailAndPassword(auth, email, password); - console.log("User signed up:", creds.user); - const userId = creds?.user.uid - if (userId) { - const lover = await getLoverRow(userId, db) - if (!lover) { - await Router.push('/signup') - } else { - await Router.push('/') - } - } - } catch (error) { - console.error("Error signing up:", error); - } -}; - export default function RegisterPage() { return ( @@ -41,7 +23,7 @@ export default function RegisterPage() { ); } -const href = '/signup'; +// const href = '/signup'; function RegisterComponent() { const searchParams = useSearchParams(); @@ -55,6 +37,26 @@ function RegisterComponent() { // window.location.href = href; // } + const handleEmailPasswordSignUp = async (email: string, password: string) => { + try { + const creds = await createUserWithEmailAndPassword(auth, email, password); + console.log("User signed up:", creds.user); + await Router.push('/') + const userId = creds?.user.uid + if (userId) { + const lover = await getLoverRow(userId, db) + if (!lover) { + await Router.push('/signup') + } + } + } catch (error) { + console.error("Error signing up:", error); + if (error instanceof Error && error.message.includes("email-already-in-use")) { + throw new Error("This email is already registered"); + } + } + }; + async function handleSubmit(event: React.FormEvent) { function handleError(error: unknown) { console.error("Registration error:", error);