blob: f0b2bbac305d7f3871ee5454550f760e108237d2 (
plain) (
tree)
|
|
import React, { useState } from 'react';
import { TextField, Button, Container, Typography } from '@mui/material';
import { createUserWithEmailAndPassword } from 'firebase/auth';
import { auth } from '../firebase';
const RegisterPage = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const handleRegister = async () => {
if (password.length < 8) {
setError('The password should be minimum 8 digits');
return;
}
try {
await createUserWithEmailAndPassword(auth, email, password);
} catch (error) {
setError(error.message);
}
};
return (
<Container>
<Typography variant="h4">Register</Typography>
<TextField
label="Email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
fullWidth
/>
<TextField
label="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
fullWidth
/>
{error && <Typography color="error">{error}</Typography>}
<Button onClick={handleRegister} variant="contained">Register</Button>
</Container>
);
};
export default RegisterPage;
|