feat(accounts): locked registration, for staging (#27)
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:
1 parent
02e8269d4d
commit
f3cc3f9f17
11 files changed
+111
-22
No files matched your search
+13
-4
@@ -19,7 +19,8 @@ export type AuthConfig = {
|
||||
secret: string;
|
||||
/** Rate limits on sign-up, sign-in and the rest (on unless false: tests turn them off). */
|
||||
rateLimit?: boolean;
|
||||
/** Whether new accounts wait for approval (default: the hub's settings, with no environment defaults). */
|
||||
/** Whether new accounts wait for approval, and whether unapproved ones may sign in to other sites (default: the
|
||||
* hub's settings, with no environment defaults). */
|
||||
settings?: Settings;
|
||||
/** Discord sign-in (an application at discord.com/developers, redirecting to API_URL/api/auth/callback/discord);
|
||||
* off without it. */
|
||||
@@ -145,10 +146,10 @@ export function createAuth(db: Database, config: AuthConfig) {
|
||||
create: {
|
||||
before: async (u, ctx) => {
|
||||
// Made by signing in with Discord (the OAuth callback): a basic account. It can use T5DE's other sites
|
||||
// at once; the hub's features wait until it finishes setting up (and then for approval, if registration
|
||||
// is closed).
|
||||
// at once (unless registration is locked: then it waits for approval first); the hub's features wait
|
||||
// until it finishes setting up (and then for approval, if registration is closed).
|
||||
if (ctx?.path?.startsWith("/callback/"))
|
||||
return { data: { ...u, role: "user", approved: true, kind: "basic" } };
|
||||
return { data: { ...u, role: "user", approved: (await settings.registration()) !== "locked", kind: "basic" } };
|
||||
// The first member runs the hub; with registration closed, the others wait for approval.
|
||||
const [row] = await db.select({ n: count() }).from(schema.user).where(eq(schema.user.kind, "member"));
|
||||
const first = (row?.n ?? 0) === 0;
|
||||
@@ -181,6 +182,14 @@ export function createAuth(db: Database, config: AuthConfig) {
|
||||
oauthProvider({
|
||||
loginPage: `${config.webURL}/signin`,
|
||||
consentPage: `${config.webURL}/consent`,
|
||||
// With registration locked (staging), only approved accounts sign in to T5DE's other sites: anyone else is
|
||||
// sent to the website, which says they're waiting for approval, and no code is issued. Checked again on
|
||||
// every authorize request, including /oauth2/continue, so there's no way past it but approval.
|
||||
postLogin: {
|
||||
page: `${config.webURL}/`,
|
||||
consentReferenceId: () => undefined,
|
||||
shouldRedirect: async ({ user }) => user.approved !== true && (await settings.registration()) === "locked",
|
||||
},
|
||||
scopes: [...oauthScopes],
|
||||
cachedTrustedClients: new Set((config.clients ?? []).map((c) => c.clientId)),
|
||||
storeClientSecret: { hash: hashSecret, verify: verifySecret },
|
||||
|
||||
Reference in new issue
Block a user