Skip to content

Return mashlib HTML for 401/403 responses on browser requests #12

Description

@melvincarvalho

Problem

When accessing a protected resource directly in the browser (e.g., http://jss:4000/demo/), the server returns raw JSON:

{"error":"Unauthorized","message":"Authentication required"}

This prevents users from logging in because mashlib never loads.

Expected Behavior

When a browser request (Accept: text/html) hits a 401 or 403, the server should return mashlib HTML so users can:

  1. See the data browser interface
  2. Click "Log in" to authenticate
  3. Access the protected resource after authentication

This is how NSS (Node Solid Server) behaves.

Proposed Solution

Modify handleUnauthorized in src/auth/middleware.js to:

  1. Check if request accepts text/html and mashlib is enabled
  2. Return mashlib HTML with appropriate status code (401/403) instead of JSON
  3. Pass request object to handleUnauthorized to access Accept header and mashlib settings

Files to Modify

  • src/auth/middleware.js - Update handleUnauthorized function
  • src/server.js - Pass request to handleUnauthorized call

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions