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 6f8a586 commit bca4d08
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions components/PasswordReset.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useState } from 'react';
import { Box, Button, TextField, Typography, Snackbar, Alert } from '@mui/material';
import { auth } from '../utils/firebaseConfig';
import { sendPasswordResetEmail } from 'firebase/auth';

const PasswordReset = () => {
const [email, setEmail] = useState('');
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState<string | null>(null);

const handlePasswordReset = async () => {
setLoading(true);
setError(null);
try {
await sendPasswordResetEmail(auth, email);
setSuccess(true);
} catch (err: unknown) {
setError('Failed to send password reset email. Please check the email address and try again.');
} finally {
setLoading(false);
}
};

return (
<Box sx={{ mt: 2 }}>
<Typography variant="h6" gutterBottom>
Reset Password
</Typography>
<TextField
label="Email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
fullWidth
margin="normal"
/>
<Button
variant="contained"
color="primary"
onClick={handlePasswordReset}
disabled={loading}
sx={{ mt: 2 }}
>
{loading ? 'Sending...' : 'Send Password Reset Email'}
</Button>
<Snackbar open={success} autoHideDuration={6000} onClose={() => setSuccess(false)}>
<Alert onClose={() => setSuccess(false)} severity="success" sx={{ width: '100%' }}>
Password reset email sent successfully!
</Alert>
</Snackbar>
{error && (
<Typography color="error" sx={{ mt: 2 }}>
{error}
</Typography>
)}
</Box>
);
};

export default PasswordReset;

0 comments on commit bca4d08

Please sign in to comment.