Updated frontend
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useAuth } from '../context/useAuth';
|
||||
import { ShieldCheck, UserCheck, Lock, User, ArrowRight, Sparkles } from 'lucide-react';
|
||||
|
||||
export function LoginPage() {
|
||||
@@ -29,13 +29,17 @@ export function LoginPage() {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const user = await login(username, password, selectedRole);
|
||||
const user = await login(username, password);
|
||||
setLoading(false);
|
||||
// Route by the role the SERVER assigned, not by the tab that was
|
||||
// selected. The tab only labels which account you are signing in to.
|
||||
if (user.role === 'admin') navigate('/admin');
|
||||
else navigate('/user');
|
||||
} catch (err) {
|
||||
setLoading(false);
|
||||
setError(`Login failed. Invalid username or password for ${selectedRole.toUpperCase()} account.`);
|
||||
// Surface the server's own message: it distinguishes bad credentials
|
||||
// from the lockout after repeated failures, which a generic string hides.
|
||||
setError(err?.message || 'Login failed. Check your username and password.');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user