@@ -17,34 +17,19 @@ import {LovePage} from "web/components/love-page";
1717async function redirectSignin ( creds : any ) {
1818 console . log ( "User signed in:" , creds . user ) ;
1919 const userId = creds ?. user . uid
20+ await Router . push ( '/' )
2021 if ( userId ) {
21- const lover = await getLoverRow ( userId , db )
22- if ( ! lover ) {
23- await Router . push ( '/signup' )
24- } else {
25- await Router . push ( '/' )
22+ try {
23+ const lover = await getLoverRow ( userId , db )
24+ if ( ! lover ) {
25+ await Router . push ( '/signup' )
26+ }
27+ } catch ( error ) {
28+ console . error ( "Error fetching lover profile:" , error ) ;
2629 }
2730 }
2831}
2932
30- const handleEmailPasswordSignIn = async ( email : string , password : string ) => {
31- try {
32- const creds = await signInWithEmailAndPassword ( auth , email , password ) ;
33- await redirectSignin ( creds )
34- } catch ( error ) {
35- console . error ( "Error signing in:" , error ) ;
36- }
37- } ;
38-
39- const handleGoogleSignIn = async ( ) => {
40- try {
41- const creds = await firebaseLogin ( ) ;
42- await redirectSignin ( creds )
43- } catch ( error ) {
44- console . error ( "Error signing in:" , error ) ;
45- }
46- } ;
47-
4833
4934export default function LoginPage ( ) {
5035 return (
@@ -58,6 +43,7 @@ function RegisterComponent() {
5843 const searchParams = useSearchParams ( ) ;
5944 const [ error , setError ] = useState < string | null > ( null ) ;
6045 const [ isLoading , setIsLoading ] = useState ( false ) ;
46+ const [ isLoadingGoogle , setIsLoadingGoogle ] = useState ( false ) ;
6147
6248 useEffect ( ( ) => {
6349 const error = searchParams . get ( 'error' ) ;
@@ -68,6 +54,32 @@ function RegisterComponent() {
6854 }
6955 } , [ searchParams ] ) ;
7056
57+ const handleGoogleSignIn = async ( ) => {
58+ setIsLoadingGoogle ( true ) ;
59+ setError ( null ) ;
60+ try {
61+ const creds = await firebaseLogin ( ) ;
62+ await redirectSignin ( creds )
63+ } catch ( error ) {
64+ let message = 'Failed to sign in with Google' ;
65+ console . error ( "Error signing in:" , error ) ;
66+ setError ( message ) ;
67+ setIsLoadingGoogle ( false ) ;
68+ }
69+ } ;
70+
71+ const handleEmailPasswordSignIn = async ( email : string , password : string ) => {
72+ try {
73+ const creds = await signInWithEmailAndPassword ( auth , email , password ) ;
74+ await redirectSignin ( creds )
75+ } catch ( error ) {
76+ let message = 'Failed to sign in with your email and password' ;
77+ console . error ( "Error signing in:" , message ) ;
78+ setError ( message ) ;
79+ setIsLoading ( false ) ;
80+ }
81+ } ;
82+
7183 async function handleSubmit ( event : React . FormEvent < HTMLFormElement > ) {
7284 try {
7385 event . preventDefault ( ) ;
0 commit comments