From b84fe9a9c4c18a3f4e957f76ead34403c4316f76 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 20 Dec 2023 19:40:11 +0200 Subject: Added a simple Login and SignUp page for the web driver app --- driver/src/pages/SignUp.tsx | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 driver/src/pages/SignUp.tsx (limited to 'driver/src/pages/SignUp.tsx') diff --git a/driver/src/pages/SignUp.tsx b/driver/src/pages/SignUp.tsx new file mode 100644 index 0000000..3ee09dc --- /dev/null +++ b/driver/src/pages/SignUp.tsx @@ -0,0 +1,84 @@ +import { useState, useEffect } from 'react'; +import { auth } from '../firebase/firebase_config'; +import { createUserWithEmailAndPassword } from 'firebase/auth'; + + +const SignUp = () => { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + useEffect(() => { + const unsubscribe = auth.onAuthStateChanged((user) => { + if (user) { + // User is signed in. + console.log('User is signed in:', user); + // TODO: redirect the user to another page or perform some other action + } else { + // No user is signed in. + console.log('No user is signed in'); + } + }); + + return () => { + unsubscribe(); + }; + }, []); + + const handleSignUp = async () => { + try { + // The onAuthStateChanged listener will handle the signed-in user state. + const userCredential = await createUserWithEmailAndPassword(auth, email, password); + console.log('User signed up:', userCredential.user); + } catch (error) { + // TODO: Handle error messages or display them to the user. + console.error('Error signing up:', error); + } + }; + + return ( +
+
+

Sign Up

+
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+
+ +
+
+
+
+ ); +}; + +export default SignUp; -- cgit v1.2.3