-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9aed42b
commit 03d7d2c
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useState } from 'react'; | ||
import { Box, Button, TextField, Typography, CircularProgress, Snackbar, Alert } from '@mui/material'; | ||
import { auth } from '../utils/firebaseConfig'; | ||
import { createUserWithEmailAndPassword } from 'firebase/auth'; | ||
|
||
const SignUp = () => { | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const [success, setSuccess] = useState(false); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
const handleSignUp = async () => { | ||
setLoading(true); | ||
setError(null); | ||
try { | ||
await createUserWithEmailAndPassword(auth, email, password); | ||
setSuccess(true); | ||
} catch (err: unknown) { | ||
setError('Failed to sign up. Please check the details and try again.'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box sx={{ mt: 2 }}> | ||
<Typography variant="h6" gutterBottom> | ||
Sign Up | ||
</Typography> | ||
<TextField | ||
label="Email" | ||
type="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
fullWidth | ||
margin="normal" | ||
/> | ||
<TextField | ||
label="Password" | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
fullWidth | ||
margin="normal" | ||
/> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={handleSignUp} | ||
disabled={loading} | ||
sx={{ mt: 2 }} | ||
> | ||
{loading ? <CircularProgress size={24} /> : 'Sign Up'} | ||
</Button> | ||
<Snackbar open={success} autoHideDuration={6000} onClose={() => setSuccess(false)}> | ||
<Alert onClose={() => setSuccess(false)} severity="success" sx={{ width: '100%' }}> | ||
Sign up successful! | ||
</Alert> | ||
</Snackbar> | ||
{error && ( | ||
<Typography color="error" sx={{ mt: 2 }}> | ||
{error} | ||
</Typography> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default SignUp; |