fix(api): Login redirect loop (#5190)
๐ Bug-fix PR
Closes #5190
๐ Summary
When the MCP_CLIENT_AUTH_ENABLED flag is set to false, logging into the admin UI goes into an infinite redirect loop between /admin and /admin/login.
๐ Reproduction Steps
- Set
MCP_CLIENT_AUTH_ENABLEDtofalse - Access the admin UI
- Open the browser network tab
- Login
- Watch the browser network tab
๐ Root Cause
The loop is:
-
GET
/admin: route dependencyget_current_user_with_permissionsentersmcp_client_auth_enabled=Falseblock, hitsis_proxy_auth_trust_active()=Falseโ redirects browser to/admin/login. The JWT cookie is present but the function returns early before ever reaching the JWT-reading code. -
GET
/admin/login:admin_login_pagereads the JWT cookie, validates it, seesis_admin=Trueโ redirects to/admin
๐ก Fix Description
Before entering the mcp_client_auth_enabled=False block, check if a JWT token is already present. If it is, skip the block and fall through to standard JWT validation.
๐งช Verification
| Check | Command | Status |
|---|---|---|
| Lint suite | make lint |
โ |
| Unit tests | make test |
โ |
| Coverage โฅ 80 % | make coverage |
โ |
| Manual regression no longer fails | steps / screenshots | โ |
๐ MCP Compliance (if relevant)
- [ ] Matches current MCP spec
- [ ] No breaking change to MCP clients
โ Checklist
- [X] Code formatted (
make black isort pre-commit) - [X] No secrets/credentials committed