Fix register endpoint
Some checks failed
release-image / release-image (push) Has been cancelled

This commit is contained in:
Logan Cusano
2025-05-26 18:59:37 -04:00
parent ea5d79b7c1
commit d96d3c4bf2

View File

@@ -5,14 +5,18 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
import { Label } from '@/components/ui/label';
import { useAuth } from '@/context/AuthContext'; // Assuming useAuth provides authAwareFetch if needed for registration
import { useAuth } from '@/context/AuthContext';
// You'll need to import authAwareFetch directly or ensure your useAuth hook provides it for registration if not handling it internally.
// For this example, we'll assume direct import as it's a separate utility.
import { authAwareFetch } from '@/utils/AuthAwareFetch'; // Import authAwareFetch
const LoginPage: React.FC = () => {
const [username, setUsername] = useState<string>('');
const [password, setPassword] = useState<string>('');
const [error, setError] = useState<string>('');
const [isRegistering, setIsRegistering] = useState<boolean>(false); // New state for registration mode
const { login } = useAuth();
const [isRegistering, setIsRegistering] = useState<boolean>(false);
const { login, logout } = useAuth(); // Destructure logout from useAuth to pass it to authAwareFetch
const handleSubmit = async (e: React.FormEvent): Promise<void> => {
e.preventDefault();
@@ -30,18 +34,20 @@ const LoginPage: React.FC = () => {
const handleRegister = async (): Promise<void> => {
try {
// Assuming you have access to a fetch-like function or authAwareFetch from your context
// If not, you might need to import a standard fetch or define it.
const response = await fetch('/auth/register_user', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
const response = await authAwareFetch(
'/auth/register_user', // The registration endpoint
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
isLoginAttempt: true, // Mark as login attempt to bypass 401 handling for expected responses
},
body: JSON.stringify({ username, password }),
});
logout // Pass the logout function from AuthContext
);
if (response.ok) {
// Registration successful, maybe log them in automatically or show a success message
alert('Registration successful! You can now log in.');
setIsRegistering(false); // Switch back to login form
setUsername('');