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]>
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
// The hub's settings that admins change from the console, kept in hub_setting. A setting never changed there has its
|
|
// default from the environment (so a new staging hub can start with registration closed).
|
|
import { eq, schema, type Database } from "@t5de/db";
|
|
|
|
const { hubSetting } = schema;
|
|
|
|
/**
|
|
* Open: new accounts can use the hub at once. Closed: they can sign in, and wait for a moderator's approval (accounts
|
|
* from Discord sign-in can still use T5DE's other sites at once). Locked, for staging: every new account waits for
|
|
* approval, Discord ones too, and only approved accounts sign in to T5DE's other sites (auth.ts, postLogin).
|
|
*/
|
|
export type Registration = "open" | "closed" | "locked";
|
|
export const registrations: readonly Registration[] = ["open", "closed", "locked"];
|
|
|
|
export class Settings {
|
|
constructor(
|
|
private readonly db: Database,
|
|
private readonly defaults: { registration?: string } = {},
|
|
) {}
|
|
|
|
async registration(): Promise<Registration> {
|
|
const [row] = await this.db.select().from(hubSetting).where(eq(hubSetting.key, "registration"));
|
|
const value = row?.value ?? this.defaults.registration;
|
|
return value === "closed" || value === "locked" ? value : "open";
|
|
}
|
|
|
|
async setRegistration(value: Registration) {
|
|
await this.db
|
|
.insert(hubSetting)
|
|
.values({ key: "registration", value })
|
|
.onConflictDoUpdate({ target: hubSetting.key, set: { value, updatedAt: new Date() } });
|
|
}
|
|
}
|