Redirect to login with success message after signup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Krao Hasanee
2026-03-26 23:50:23 -04:00
parent ee99465f8a
commit d7f89ad0da
2 changed files with 5 additions and 2 deletions
+4 -1
View File
@@ -1,10 +1,12 @@
import { useState } from 'react'; import { useState } from 'react';
import { useNavigate, Link } from 'react-router-dom'; import { useNavigate, useLocation, Link } from 'react-router-dom';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
export default function Login() { export default function Login() {
const { login } = useAuth(); const { login } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const successMessage = location.state?.message || '';
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [error, setError] = useState(''); const [error, setError] = useState('');
@@ -73,6 +75,7 @@ export default function Login() {
required required
/> />
</div> </div>
{successMessage && <p style={{ color: '#22c55e', fontSize: 13, marginBottom: 12 }}>{successMessage}</p>}
{error && <p style={{ color: '#ef4444', fontSize: 13, marginBottom: 12 }}>{error}</p>} {error && <p style={{ color: '#ef4444', fontSize: 13, marginBottom: 12 }}>{error}</p>}
<button type="submit" className="btn btn-primary w-full btn-lg" disabled={loading}> <button type="submit" className="btn btn-primary w-full btn-lg" disabled={loading}>
{loading ? 'Signing in...' : 'Sign In'} {loading ? 'Signing in...' : 'Sign In'}
+1 -1
View File
@@ -19,7 +19,7 @@ export default function Signup() {
setError(''); setError('');
const { error: err } = await signup(form.email, form.password, form.name); const { error: err } = await signup(form.email, form.password, form.name);
if (err) { setError(err); setLoading(false); return; } if (err) { setError(err); setLoading(false); return; }
navigate('/my-projects'); navigate('/', { state: { message: 'Account created! Please sign in.' } });
}; };
return ( return (