Skip to content

Commit 0f03746

Browse files
committed
Fix register redirect and add error message for email already in use
1 parent 4a891d9 commit 0f03746

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

web/lib/util/signup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import { getLoverRow } from 'common/love/lover'
55

66
export const signupThenMaybeRedirectToSignup = async () => {
77
const creds = await firebaseLogin()
8+
await Router.push('/')
89
const userId = creds?.user.uid
910
if (userId) {
1011
const lover = await getLoverRow(userId, db)
1112
if (!lover) {
1213
await Router.push('/signup')
13-
} else {
14-
await Router.push('/')
1514
}
1615
}
1716
}

web/pages/register.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@ import {getLoverRow} from "common/love/lover";
1414
import {db} from "web/lib/supabase/db";
1515
import Router from "next/router";
1616

17-
const handleEmailPasswordSignUp = async (email: string, password: string) => {
18-
try {
19-
const creds = await createUserWithEmailAndPassword(auth, email, password);
20-
console.log("User signed up:", creds.user);
21-
const userId = creds?.user.uid
22-
if (userId) {
23-
const lover = await getLoverRow(userId, db)
24-
if (!lover) {
25-
await Router.push('/signup')
26-
} else {
27-
await Router.push('/')
28-
}
29-
}
30-
} catch (error) {
31-
console.error("Error signing up:", error);
32-
}
33-
};
34-
3517

3618
export default function RegisterPage() {
3719
return (
@@ -41,7 +23,7 @@ export default function RegisterPage() {
4123
);
4224
}
4325

44-
const href = '/signup';
26+
// const href = '/signup';
4527

4628
function RegisterComponent() {
4729
const searchParams = useSearchParams();
@@ -55,6 +37,26 @@ function RegisterComponent() {
5537
// window.location.href = href;
5638
// }
5739

40+
const handleEmailPasswordSignUp = async (email: string, password: string) => {
41+
try {
42+
const creds = await createUserWithEmailAndPassword(auth, email, password);
43+
console.log("User signed up:", creds.user);
44+
await Router.push('/')
45+
const userId = creds?.user.uid
46+
if (userId) {
47+
const lover = await getLoverRow(userId, db)
48+
if (!lover) {
49+
await Router.push('/signup')
50+
}
51+
}
52+
} catch (error) {
53+
console.error("Error signing up:", error);
54+
if (error instanceof Error && error.message.includes("email-already-in-use")) {
55+
throw new Error("This email is already registered");
56+
}
57+
}
58+
};
59+
5860
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
5961
function handleError(error: unknown) {
6062
console.error("Registration error:", error);

0 commit comments

Comments
 (0)