Fix register redirect and add error message for email already in use

This commit is contained in:
MartinBraquet
2025-09-06 12:02:06 +02:00
parent 4a891d9c9a
commit 0f03746c6a
2 changed files with 22 additions and 21 deletions

View File

@@ -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('/')
}
}
}

View File

@@ -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<HTMLFormElement>) {
function handleError(error: unknown) {
console.error("Registration error:", error);