feat(auth): close registration after the first user #28

Manually merged
jfro merged 1 commit from feat/12-close-registration into main 2026-11-01 17:48:13 +00:00
Owner

Closes #12.

Every account can change sources, AI keys and settings, so open registration made any signup an admin.

What changes

  • Accounts.register_user/1 only registers while no account exists, unless ALLOW_REGISTRATION=true (runtime.exs, all envs but test). The check runs inside a transaction holding a Postgres advisory lock, so two people can't both register "first".
  • /users/register redirects to log in with "Registration is closed. An admin can open it with ALLOW_REGISTRATION=true." when closed; the login page drops its sign-up line.
  • SSO logins still create accounts on first login: the identity provider decides who gets in (noted in the README). Say if you want those gated too.
  • README env table: ALLOW_REGISTRATION.
  • config/test.exs sets allow_registration: true since fixtures register many users; registration_gate_test.exs (sync) turns it off and covers the first user, closing, the env var, and both pages. 3 of its 4 tests fail on main.

The lock is taken only when the gate applies: taken in every register_user, it's held until the sandbox transaction ends and serialized async tests.

mix precommit passes; full suite 8 runs in a row clean.

Note: conflicts lightly with PR #25 (both touch registration.ex); I'll rebase whichever merges second.

Login after visiting /users/register with registration closed (dev, local mail adapter), desktop and 390px:
12-register-closed-desktop
12-register-closed-mobile

Closes #12. Every account can change sources, AI keys and settings, so open registration made any signup an admin. **What changes** - `Accounts.register_user/1` only registers while no account exists, unless `ALLOW_REGISTRATION=true` (runtime.exs, all envs but test). The check runs inside a transaction holding a Postgres advisory lock, so two people can't both register "first". - `/users/register` redirects to log in with "Registration is closed. An admin can open it with ALLOW_REGISTRATION=true." when closed; the login page drops its sign-up line. - SSO logins still create accounts on first login: the identity provider decides who gets in (noted in the README). Say if you want those gated too. - README env table: `ALLOW_REGISTRATION`. - `config/test.exs` sets `allow_registration: true` since fixtures register many users; `registration_gate_test.exs` (sync) turns it off and covers the first user, closing, the env var, and both pages. 3 of its 4 tests fail on main. The lock is taken only when the gate applies: taken in every register_user, it's held until the sandbox transaction ends and serialized async tests. `mix precommit` passes; full suite 8 runs in a row clean. Note: conflicts lightly with PR #25 (both touch registration.ex); I'll rebase whichever merges second. Login after visiting /users/register with registration closed (dev, local mail adapter), desktop and 390px: ![12-register-closed-desktop](https://git.knope.dev/attachments/560bfa3d-8b7e-4ba6-aa5f-e62317d16083) ![12-register-closed-mobile](https://git.knope.dev/attachments/ca55bd97-e737-43e4-9b49-0532eeca7a1b)
jfro added this to the v1.0 milestone 2026-11-01 17:31:35 +00:00
feat(auth): close registration after the first user
All checks were successful
CI / test (pull_request) Successful in 24s
9b39320b47
Every account can change sources, AI keys and settings, so open
registration made any signup an admin. Registering by email is now open
only until the first account exists (serialized with an advisory lock),
unless ALLOW_REGISTRATION=true. The register page redirects to log in
with an explanation when closed, and the login page drops its sign-up
link. SSO logins are unchanged: the identity provider decides.

Closes #12
Author
Owner

Review of #28 at 9b39320 (Nye): looks good, ready.

  • register_user/1 is the only email path that creates users; the OIDC path (find_or_register_oidc_user) stays ungated as described.
  • Race: added a test (test/review/registration_race_test.exs) that runs 6 registrations at once on real connections (Sandbox.unboxed_run), 25 rounds. With the advisory lock exactly one succeeds every round and the rest get {:error, :registration_closed}. With the lock disabled, 4 of 6 got in on round 1, so the lock is doing the work.
  • mix precommit: 628 tests pass. CI green.

Non-blocking notes:

  • An unconfirmed first signup (a typo'd email) also closes registration; ALLOW_REGISTRATION=true once recovers it. Maybe worth a README line.
  • Only "true"/"1" enable it; "TRUE"/"yes" are silently off. Could downcase.
  • Mind the registration.ex conflict with #25 on rebase.
Review of #28 at 9b39320 (Nye): looks good, ready. - `register_user/1` is the only email path that creates users; the OIDC path (`find_or_register_oidc_user`) stays ungated as described. - Race: added a test (test/review/registration_race_test.exs) that runs 6 registrations at once on real connections (Sandbox.unboxed_run), 25 rounds. With the advisory lock exactly one succeeds every round and the rest get `{:error, :registration_closed}`. With the lock disabled, 4 of 6 got in on round 1, so the lock is doing the work. - `mix precommit`: 628 tests pass. CI green. Non-blocking notes: - An unconfirmed first signup (a typo'd email) also closes registration; ALLOW_REGISTRATION=true once recovers it. Maybe worth a README line. - Only "true"/"1" enable it; "TRUE"/"yes" are silently off. Could downcase. - Mind the registration.ex conflict with #25 on rebase.
jfro force-pushed feat/12-close-registration from 9b39320b47
All checks were successful
CI / test (pull_request) Successful in 24s
to 6b140cd2a0
All checks were successful
CI / test (pull_request) Successful in 24s
2026-11-01 17:47:18 +00:00
Compare
jfro manually merged commit 262874a6a0 into main 2026-11-01 17:48:13 +00:00
Sign in to join this conversation.
No description provided.