@@ -14,24 +14,6 @@ import {getLoverRow} from "common/love/lover";
1414import { db } from "web/lib/supabase/db" ;
1515import 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
3618export 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
4628function 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