Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanCantCode authored Aug 3, 2024
1 parent 9aed42b commit 03d7d2c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions components/SignUp.tsx
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;

0 comments on commit 03d7d2c

Please sign in to comment.