Spaces:
Sleeping
Sleeping
File size: 1,990 Bytes
9f7a5a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import React, { useState } from 'react';
import { createUserWithEmailAndPassword } from "firebase/auth";
import { auth } from '/src/services/firebase.js';
import { useNavigate } from 'react-router-dom';
const SignUp = () => {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const navigate = useNavigate();
const handleSignUp = async (e) => {
e.preventDefault();
setError('');
try {
await createUserWithEmailAndPassword(auth, email, password);
navigate('/chat'); // Redirect to chat on successful sign-up
} catch (err) {
setError(err.message);
}
};
return (
<div className="auth-container">
<div className="auth-form">
<h2>Sign up</h2>
<form onSubmit={handleSignUp}>
<div className="form-group">
<label>Name</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your name"
required
/>
</div>
<div className="form-group">
<label>Email</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
required
/>
</div>
<div className="form-group">
<label>Password</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter your password"
required
/>
</div>
{error && <p className="error-message">{error}</p>}
<button type="submit" className="btn-primary">Sign Up</button>
</form>
</div>
</div>
);
};
export default SignUp; |