Skip to content

Users API

An endpoint that returns the users registered in the system. It is used when choosing whom to share a survey with on the permission screen.

See API Definition for authentication, response format, and error handling.

Method

HTTP Methods

Method URI Overview
GET /api/users List users

Resource Definition

User Schema

Field Type Notes
id string UUID
name string Display name
email string Email address, unique within the system
isAdmin boolean Whether the user is an administrator

Authentication

User authentication via the x-user-email / x-user-name headers is required. Any authenticated user may fetch the list.

List Users

Overview

Returns the list of registered users.

Users are not registered explicitly; they are created automatically the first time an authenticated request arrives. The list therefore contains every user who has logged into the system at least once.

URI

GET /api/users

Response (200 OK)

{
  "ok": true,
  "data": [
    { "id": "โ€ฆ", "name": "่จญ่จˆ ๅคช้ƒŽ", "email": "taro@example.com", "isAdmin": false },
    { "id": "โ€ฆ", "name": "็ฎก็† ๆฌก้ƒŽ", "email": "jiro@example.com", "isAdmin": true }
  ]
}

Error Handling

Description Status code Status name
Authentication headers missing 401 Unauthorized

Processing Flow

The authentication middleware performs the following on every request.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware as Auth middleware
    participant DB

    Client->>Middleware: Request (x-user-email / x-user-name)
    alt Headers missing
        Middleware-->>Client: 401 Unauthorized
    else
        Middleware->>Middleware: URL-decode values containing %
        Middleware->>Middleware: Lower-case the email address
        Middleware->>Middleware: Compare with SURVEY_ADMIN_EMAILS
        Middleware->>DB: Look up the user
        alt Exists
            Middleware->>DB: Update name / admin flag if changed
        else Does not exist
            Middleware->>DB: Create the user
        end
        Middleware->>Middleware: Proceed to the handler
    end

HTTP header character encoding

HTTP headers can only carry ISO-8859-1, so display names containing Japanese are encodeURIComponent-ed by the frontend. The backend attempts to decode only values containing %, and falls back to the original string if decoding fails.

Impersonation is possible

The current authentication trusts the headers, so forging them allows acting as any user. This is an open issue to address before a production rollout (Infrastructure).