Skip to content

Thread history inaccessible for anonymous users with dataPersistence enabled #2964

Description

@MS33834

Description
When dataPersistence is enabled but requireLogin is false, the behavior for anonymous users is inconsistent:

  1. Frontend: The thread history sidebar is hidden because the rendering logic requires requireLogin.
  2. Backend: The get_current_user function returns None for anonymous users, causing /project/threads to return a 401 Unauthorized error, even though anonymous threads are successfully created in the data layer.

This breaks the "persistent anonymous chat" use case: messages are stored, but the user cannot retrieve or resume them.

Steps to Reproduce

  1. Configure Chainlit with dataPersistence: true and requireLogin: false.
  2. Open the UI as an anonymous user.
  3. Send a message (a thread is created in the database).
  4. Attempt to open the sidebar history (entry is not rendered).
  5. Call POST /project/threads without authentication (returns 401).

Expected Behavior
Either:

  • Anonymous users should be able to list and resume their threads when dataPersistence is enabled.
  • OR the framework should explicitly document that dataPersistence requires requireLogin and prevent anonymous thread creation.

Actual Behavior
Persistence works partially (creation), but retrieval fails, leading to a confusing user experience.

Environment

  • Chainlit version: 2.11.1
  • Frontend: frontend/dist/assets/index-*.js
  • Backend: chainlit/auth/__init__.py, chainlit/socket.py

Possible Fix
If anonymous persistence is intended:

  1. Frontend: Update rendering logic to rely only on dataPersistence.
  2. Backend: Modify get_current_user to return an anonymous User object when login is not required:
    if not require_login():
        return User(identifier="anonymous", metadata={"role": "anonymous"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    authPertaining to authentication.backendPertains to the Python backend.bugSomething isn't workingfrontendPertains to the frontend.needs-triage

    Type

    No fields configured for Bug.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions