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>
22 lines
1.0 KiB
SQL
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);
|