Skip to content

[Bug]:loginToServer sends multipart/form-data instead of application/x-www-form-urlencoded #2820

@Gun249

Description

@Gun249

Bug Report: Login Form Fails Silently When AUTH_MODE is Enabled

Checklist

  • [] I have searched the existing issues and this bug is not already filed.
  • [] I believe this is a legitimate bug, not just a question or feature request.

Description

When LightRAG is deployed on a server with authentication configured via `AUTH_ACCOUNTS` and `TOKEN_SECRET` in the `.env` file, accessing the server IP via browser navigates to the login page. However, upon entering valid credentials and clicking Login, the form fails with a "Login failed, please check username and password" message on screen Inspecting the browser console reveals `ERR_EMPTY_RESPONSE` on the `POST /login` request

Root cause: The frontend sends the request as multipart/form-data, but FastAPI's OAuth2PasswordRequestForm requires application/x-www-form-urlencoded. The required grant_type=password field is also missing from the request body.


Steps to Reproduce

  1. Deploy LightRAG with the following `.env` configuration:
    
       AUTH_ACCOUNTS=
       TOKEN_SECRET=
    
  2. Open WebUI at /webui/#/login
  3. Enter valid username and password
  4. Click Login
  5. Browser returns ERR_EMPTY_RESPONSE or login fails with no token returned

Expected Behavior

Login should succeed, return a valid JWT token, and redirect the user into the WebUI.


LightRAG Config

AUTH_ACCOUNTS= 
TOKEN_SECRET=

Root Cause Analysis

File: lightrag_webui/src/api/lightrag.ts (~line 922)

code:

// Wrong: sends as multipart/form-data
const formData = new FormData()
formData.append('username', username)
formData.append('password', password)
// Missing: grant_type=password

Fixed code:

// Correct: sends as application/x-www-form-urlencoded
const formData = new URLSearchParams()
formData.append('username', username)
formData.append('password', password)
formData.append('grant_type', 'password')

Additional Information

Field Value
LightRAG Version 1.4.10 (API: 0272)
Operating System Ubuntu 20.04
Python Version 3.12
Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions