Updated frontend

This commit is contained in:
sriram
2026-08-12 16:33:39 +05:30
parent d2ac832960
commit dae0b3e0fb
14 changed files with 297 additions and 164 deletions

View File

@@ -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.');
}
};