Files
playlistd/migrations/20261116120000_users.sql
claude BotandClaude Opus 5.5 53c1bffa6d Require logging in to the web UI and API
The first visit to the UI creates the account from a username and password;
after that every API route needs a session cookie from logging in. Accounts
are stored in app_user (Argon2id password hashes) and sessions in
user_session (SHA-256 token hashes, 30 days).

The account page lets the user save a Listenbrainz token, checked with
Listenbrainz first. It takes priority over listenbrainz.token from the
config for LB Radio suggestions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:24:09 +00:00

22 lines
1.0 KiB
SQL

-- The account that logs in to the web UI. The first visit to the UI creates it.
CREATE TABLE "app_user"
(
id UUID NOT NULL PRIMARY KEY,
username VARCHAR(64) NOT NULL UNIQUE,
password_hash TEXT NOT NULL, -- Argon2id, in PHC string format
listenbrainz_token TEXT, -- Used for Listenbrainz endpoints that need one (e.g. LB Radio)
listenbrainz_user VARCHAR(250), -- The Listenbrainz user the token belongs to
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Logged in browsers. Only a hash of the session token is stored.
CREATE TABLE "user_session"
(
token_hash BYTEA NOT NULL PRIMARY KEY, -- SHA-256 of the token in the session cookie
user_id UUID NOT NULL REFERENCES "app_user" (id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
expires_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX "user_session_expires_at" ON "user_session" (expires_at);