feat(accounts): locked registration, for staging (#27)
Release / release (push) Successful in 4s
CI / test (push) Successful in 1m35s
CI / image (apps/api/Dockerfile, t5de-hub-api) (push) Successful in 5s
CI / image (apps/web/Dockerfile, t5de-hub-web) (push) Successful in 14s

Locks staging down before payments' staging (PayPal's sandbox) exists.

**The problem:** staging's registration is closed, but signing in with Discord still makes an approved basic account at once (`auth.ts`). So any Discord account can sign in to Music's staging.

**The change:** a third registration setting, `locked`:
- Every new account waits for a moderator's approval, Discord sign-ins too.
- Only approved accounts sign in to T5DE's other sites. The gate is the OAuth provider's `postLogin.shouldRedirect`: an unapproved account is sent to the website (which shows "Waiting for Approval") and no code is issued. It runs on every authorize request and on `/oauth2/continue`.
- Finishing setup under `locked` keeps the person's approval, so an approved basic account doesn't lose Music access by becoming a member.
- **Console:** the setting has a "Locked" option. **Website:** the waiting screen for unapproved Discord accounts, and the sign-up page's note.

`open` and `closed` behave as before. Under `closed`, a member waiting for approval still signs in to Music (tested), so prod doesn't change.

**After merging:** infra sets staging's `REGISTRATION` to `locked`. That's only a default: if staging's registration was ever changed in the console, set it to Locked there. Accounts already on staging keep their approval.

**Checks:** `bun test` (77 pass, two new tests), `check-types`, `lint`.

Locks staging down before payments' staging (PayPal's sandbox) exists.

**The problem:** staging's registration is closed, but signing in with Discord still makes an approved basic account at once (`auth.ts`). So any Discord account can sign in to Music's staging.

**The change:** a third registration setting, `locked`:
- Every new account waits for a moderator's approval, Discord sign-ins too.
- Only approved accounts sign in to T5DE's other sites. The gate is the OAuth provider's `postLogin.shouldRedirect`: an unapproved account is sent to the website (which shows "Waiting for Approval") and no code is issued. It runs on every authorize request and on `/oauth2/continue`.
- Finishing setup under `locked` keeps the person's approval, so an approved basic account doesn't lose Music access by becoming a member.
- **Console:** the setting has a "Locked" option. **Website:** the waiting screen for unapproved Discord accounts, and the sign-up page's note.

`open` and `closed` behave as before. Under `closed`, a member waiting for approval still signs in to Music (tested), so prod doesn't change.

**After merging:** infra sets staging's `REGISTRATION` to `locked`. That's only a default: if staging's registration was ever changed in the console, set it to Locked there. Accounts already on staging keep their approval.

**Checks:** `bun test` (77 pass, two new tests), `check-types`, `lint`.

Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #27.
This commit is contained in:
dhkatz authored and dhkatz committed 2026-11-20 20:31:32 +00:00
1 parent 02e8269d4d
commit f3cc3f9f17
11 files changed
+111 -22

No files matched your search

+20 -1
View File
@@ -2,7 +2,7 @@
// verified email only, and never links by matching email; a basic account finishes setting up with a username and
// password; a member links Discord from their own session. Discord itself is stood in for below.
import { afterAll, beforeAll, expect, test } from "bun:test";
import { openDatabase, type Database } from "@t5de/db";
import { eq, openDatabase, schema, type Database } from "@t5de/db";
import { createApp } from "../src/app";
import { createAuth } from "../src/auth";
import { ImvuClient } from "../src/imvu";
@@ -203,3 +203,22 @@ test("a member links Discord from their own session; a Discord account already i
expect(refused.searchParams.get("error")).toBe("account_already_linked_to_different_user");
expect((await call(fay, "GET", "/api/v1/account")).json.discord.linked).toBe(false);
});
test("with registration locked, a Discord sign-in waits for approval too, and finishing setup keeps the approval", async () => {
await settings.setRegistration("locked");
try {
const gil: Cookie = { v: "" };
await viaDiscord(gil, { id: "1008", username: "gil", email: "[email protected]", verified: true });
const me = (await call(gil, "GET", "/api/v1/me")).json.person;
expect(me).toMatchObject({ kind: "basic", approved: false });
// Approved by a moderator, then finishing setup: still approved.
await db.update(schema.user).set({ approved: true }).where(eq(schema.user.id, me.id));
expect((await call(gil, "POST", "/api/v1/account/finish", { username: "gil", password: "a long password" })).json.person).toMatchObject({
kind: "member",
approved: true,
});
} finally {
await settings.setRegistration("open");
}
});
+37 -1
View File
@@ -20,10 +20,11 @@ let db: Database;
let close: () => Promise<void>;
let base: string;
let stop: () => void;
let settings: Settings;
beforeAll(async () => {
({ db, close } = await openDatabase("memory"));
const settings = new Settings(db, { registration: "open" });
settings = new Settings(db, { registration: "open" });
const auth = createAuth(db, { apiURL, webURL, secret: "test-secret-test-secret-test-secret-1234", rateLimit: false, settings, clients: [music] });
await seedClients(db, apiURL, [music]);
const imvu = new ImvuClient("http://imvu.test", (async () => Response.json({ denormalized: {} })) as unknown as typeof fetch);
@@ -185,3 +186,38 @@ test("a website session still links as before", async () => {
expect((await call(dee, "GET", "/api/v1/account/imvu")).status).toBe(200);
});
test("with registration locked, only approved accounts sign in to Music; closed doesn't stop anyone", async () => {
// Closed (prod): a member waiting for the hub's approval still signs in to Music.
await settings.setRegistration("closed");
const eli = await signUp("eli");
expect((await call(eli, "GET", "/api/v1/me")).json.person.approved).toBe(false);
await musicSignIn(eli);
await settings.setRegistration("locked");
try {
const fin = await signUp("fin");
const id = (await call(fin, "GET", "/api/v1/me")).json.person.id;
// Sent to the website (which says they're waiting), with no code for Music.
const a = await authorizeURL("openid profile imvu");
const r = await call(fin, "GET", a.path);
expect(r.status).toBe(302);
const to = new URL(r.location);
expect(to.origin + to.pathname).toBe(`${webURL}/`);
expect(to.searchParams.get("code")).toBeNull();
// Continuing from that page doesn't get past it either.
const cont = await call(fin, "POST", "/api/auth/oauth2/continue", { postLogin: true, oauth_query: to.search.slice(1) });
const again = new URL(cont.json.url);
expect(again.origin + again.pathname).toBe(`${webURL}/`);
expect(again.searchParams.get("code")).toBeNull();
// Nor does eli, approved for nothing: locked holds back everyone unapproved.
const b = await call(eli, "GET", (await authorizeURL("openid")).path);
expect(new URL(b.location).origin + new URL(b.location).pathname).toBe(`${webURL}/`);
// Once a moderator approves, it works.
await db.update(schema.user).set({ approved: true }).where(eq(schema.user.id, id));
await musicSignIn(fin);
} finally {
await settings.setRegistration("open");
}
});