Hide sign up link when registration is disabled

- Check registration status on login page load
- Only show sign up link if registration is enabled

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-21 22:52:17 -05:00
parent afda0b3f01
commit 0a762eba76

View file

@ -1,5 +1,6 @@
import { useState, useEffect, FormEvent } from 'react';
import { Link } from 'react-router-dom';
import { authApi } from '../api/client';
interface AuthFormProps {
mode: 'login' | 'register';
@ -12,6 +13,7 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
const [confirmPassword, setConfirmPassword] = useState('');
const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [registrationEnabled, setRegistrationEnabled] = useState<boolean | null>(null);
const [theme, setTheme] = useState<'light' | 'dark'>(() => {
const saved = localStorage.getItem('theme');
return (saved as 'light' | 'dark') || 'light';
@ -22,6 +24,13 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
localStorage.setItem('theme', theme);
}, [theme]);
useEffect(() => {
// Check if registration is enabled
authApi.getRegistrationStatus()
.then(res => setRegistrationEnabled(res.data.registration_enabled))
.catch(() => setRegistrationEnabled(true)); // Default to true on error
}, []);
const toggleTheme = () => {
setTheme((prev) => (prev === 'light' ? 'dark' : 'light'));
};
@ -206,17 +215,16 @@ export default function AuthForm({ mode, onSubmit }: AuthFormProps) {
</button>
</form>
<div className="auth-form-footer">
{mode === 'login' ? (
<>
Don't have an account? <Link to="/register">Sign up</Link>
</>
) : (
<>
Already have an account? <Link to="/login">Sign in</Link>
</>
)}
</div>
{mode === 'login' && registrationEnabled && (
<div className="auth-form-footer">
Don't have an account? <Link to="/register">Sign up</Link>
</div>
)}
{mode === 'register' && (
<div className="auth-form-footer">
Already have an account? <Link to="/login">Sign in</Link>
</div>
)}
</div>
</div>
);