This commit is contained in:
2026-01-29 01:49:52 -05:00
parent 31c37d9bdd
commit 3e3f37a570
13 changed files with 365 additions and 57 deletions
+3 -4
View File
@@ -1,26 +1,26 @@
import React, { useState } from 'react';
import { useNavigate, Link } from 'react-router-dom';
import toast from 'react-hot-toast';
import { useAuth } from '../AuthContext';
export default function Register() {
const [email, setEmail] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const { register } = useAuth();
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
setError('');
setLoading(true);
try {
await register(email, username, password);
toast.success('Account created successfully!');
navigate('/challenges');
} catch (err) {
setError(err.message);
toast.error(err.message || 'Registration failed');
} finally {
setLoading(false);
}
@@ -62,7 +62,6 @@ export default function Register() {
minLength={6}
/>
</div>
{error && <div className="error">{error}</div>}
<button type="submit" className="btn btn-primary" style={{ width: '100%', marginTop: '1rem' }} disabled={loading}>
{loading ? 'Creating account...' : 'Register'}
</button>