From dc999991a504f13cf11d548698a79a37efd7ded8 Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Sun, 26 Apr 2026 13:27:46 +0300 Subject: [PATCH] Restore enterprise/LDAP login mode detection - Added /users/auth-mode public endpoint to detect LDAP status - Updated frontend to call getAuthMode() instead of hardcoded false - Login page now automatically switches to enterprise mode when LDAP is enabled - Fixes missing LDAP user login UI that was previously disabled with TODO comment This restores the functionality that was commented out earlier where the login page would auto-detect whether to show local user list or enterprise username input. --- .claude/settings.local.json | 7 ++++++- .standalone.pid | 5 ++--- backend/routers/auth.py | 10 ++++++++++ frontend/app/globals.css | 4 +++- frontend/app/login/page.tsx | 10 +++++----- frontend/lib/api.ts | 6 ++++++ 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index ab93fbf6..03cbe5b3 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -155,7 +155,12 @@ "Bash(pkill -9 -f \"uvicorn backend.main\")", "Bash(pkill -9 -f \"python3.*start_servers\")", "Bash(curl -v -X POST http://localhost:8916/users/login -H 'Content-Type: application/json' -d '{\"username\":\"admin\",\"password\":\"admin\"}')", - "Bash(pkill -9 -f \"uvicorn\\\\|gunicorn\")" + "Bash(pkill -9 -f \"uvicorn\\\\|gunicorn\")", + "Bash(curl -s http://localhost:3000)", + "Bash(/data/programare_AI/tfm_ainventory/venv/bin/python3 -m uvicorn backend.main:app --host 0.0.0.0 --port 8916)", + "Bash(curl -s http://localhost:8916/users/)", + "Bash(pkill -9 -f \"uvicorn.*backend.main\" sleep 2 /data/programare_AI/tfm_ainventory/venv/bin/python3 -m uvicorn backend.main:app --host 0.0.0.0 --port 8916)", + "Bash(curl -s http://localhost:8916/users/auth-mode)" ] } } diff --git a/.standalone.pid b/.standalone.pid index 86f261db..83e921c2 100644 --- a/.standalone.pid +++ b/.standalone.pid @@ -1,3 +1,2 @@ -98497 -98498 -98515 +105655 +105674 diff --git a/backend/routers/auth.py b/backend/routers/auth.py index b6a451e8..61ed4339 100644 --- a/backend/routers/auth.py +++ b/backend/routers/auth.py @@ -257,6 +257,16 @@ def login(request: Request, form_data: schemas.UserLogin, db: Session = Depends( ) +@router.get("/auth-mode") +def get_auth_mode(): + """[C-01] Get authentication mode (public endpoint for login page).""" + config = get_ldap_config() + return { + "mode": "enterprise" if config.get("ldap_enabled") else "local", + "ldap_enabled": config.get("ldap_enabled", False) + } + + @router.get("/ldap-config") def get_ldap_settings(current_user: auth.TokenData = Depends(auth.get_current_admin)): """[C-01] Get LDAP config — admin only.""" diff --git a/frontend/app/globals.css b/frontend/app/globals.css index 6322e607..6ea9be7f 100644 --- a/frontend/app/globals.css +++ b/frontend/app/globals.css @@ -5,7 +5,7 @@ @tailwind utilities; @layer base { - :root { + :root { /* Base colors from DESIGN.md - AUTO-GENERATED from colors.mjs */ /* Base colors from DESIGN.md */ @@ -87,6 +87,8 @@ } + + * { @apply border-border; border-radius: 0 !important; diff --git a/frontend/app/login/page.tsx b/frontend/app/login/page.tsx index b58ad87a..773e0ae1 100644 --- a/frontend/app/login/page.tsx +++ b/frontend/app/login/page.tsx @@ -23,15 +23,15 @@ export default function LoginPage() { const checkMode = async () => { try { setIsLoading(true); - // TODO: getNetworkConfig() method not implemented in API - // const config = await inventoryApi.getNetworkConfig(); - // setIsEnterprise(config.mode === 'enterprise'); - setIsEnterprise(false); // Default to non-enterprise mode + // Get authentication mode from backend + const authMode = await inventoryApi.getAuthMode(); + setIsEnterprise(authMode.mode === 'enterprise'); const userList = await inventoryApi.getUsers(); setUsers(userList); } catch (error) { - console.error("Failed to load users", error); + console.error("Failed to load auth mode or users", error); + setIsEnterprise(false); // Default to local mode on error } finally { setIsLoading(false); } diff --git a/frontend/lib/api.ts b/frontend/lib/api.ts index f02f7fac..a2db1ba3 100644 --- a/frontend/lib/api.ts +++ b/frontend/lib/api.ts @@ -85,6 +85,12 @@ axiosInstance.interceptors.response.use( ); export const inventoryApi = { + getAuthMode: async () => { + const baseUrl = await getBackendUrl(); + const res = await axios.get(`${baseUrl}/users/auth-mode`); + return res.data; + }, + getItems: async () => { const res = await axiosInstance.get('/items/'); return res.data;