Context
Until now the only way into the system was the seeded admin: ADR-0007 built login, refresh and logout, and the technical plan recorded that "there is no path to create an account — every use case starts with Login". Every student story is blocked behind that. The plan also answers the question directly (§16): students may register themselves, STUDENT only, with no email verification, because the project has no mail provider and will not buy one.
Two constraints shape the rest. The seed script already refuses a SEED_ADMIN_PASSWORD under 12 characters, while loginSchema accepts 8 — so the repo carried two numbers with no stated rule. And Google sign-in, listed in ADR-0007 and the architecture notes as "phase 2", is dropped from the plan: the User.googleSub column stays, unused, rather than being removed and re-migrated later.
Decision
- Self-registration is
POST /auth/register, public, withemail,nameandpassword. It answers201with the sameAuthSessionlogin returns, so the new account is signed in without a second round trip. - STUDENT only.
registerSchemahas norolefield, so Zod strips one from the body, and the service writesRole.STUDENTliterally. Instructors are promoted by an admin; that is a different route, in a different module, behind@Roles(). emailVerifiedAtis stamped at registration. There is no mail provider, so a "pending verification" state would be a state nothing can ever leave. The column stays, and means "this address was accepted at this time" — the day a provider exists, only registration changes.- Password minimum 12 on anything we set (
PASSWORD_MIN_LENGTHinpackages/shared), on both registration and password change, matching the rule the seed script has always enforced. Login keeps its ≥8 check: it is not a policy but a "you clearly did not type a password" filter, and raising it would lock out any account created under the old rule. The maximum is 72 because bcrypt reads no further, and silently truncating would make two different passwords the same one. - No password reset flow. A reset is an email, and there is no email. A user who forgets a password asks an admin, who will get an admin-side reset route when the admin module lands.
- Duplicate email is decided by the unique index, not by a
findFirstbefore the insert. The password is hashed first either way, so a taken address and a free one cost the same time — a pre-check answers "taken" without paying for bcrypt, which turns the sign-up form into an account-enumeration stopwatch. The answer is409withcode: "EMAIL_TAKEN". - A
codeon the error envelope.apiErrorSchemagains an optionalcodefromERROR_CODESinpackages/shared, set by throwingnew ConflictException({ code, message }). It is for the failures a client must act on differently — a taken email highlights a field, an unknown major reloads a list.messagestays human and may be reworded freely. POST /auth/registeris throttled to 10 per hour per client, not per minute: registration abuse is bulk account creation, and a whole campus can share one NAT address./users/meis a new module:GETreturns the full profile,PATCHwrites onlyname,avatarUrl,majorId,semesterId,timezone, andPOST /users/me/passwordchanges the password and then revokes every refresh token of that account.majorIdandsemesterIdmust name a row that exists and isisActive; otherwise422with a code.- Refresh-token reuse detection is unchanged (ADR-0007).
replacedAtis now written when a token is spent by rotation, so a revoked row can be told apart from one the reuse sweep killed. It is observability only: nothing reads it to decide access, and there is no grace window — a replayed token still revokes the whole chain. - Google OAuth is dropped.
User.googleSubis left in place, unused and unique.
Alternatives considered
- Verification email with a pending state. Rejected: no mail provider, and the plan says one will not be bought. A state with no exit is worse than no state.
- Raising the login minimum to 12 as well. Rejected: it locks out every account created under the old rule, including the one an examiner might be holding, and it buys nothing — the policy belongs where a password is written.
- Self-service password reset with a token emailed out. Rejected for the same reason as verification. An admin-side reset covers the real case.
- Letting
rolethrough and validating it. Rejected: the safest field is the one the schema does not have. - A short reuse grace window keyed on
replacedAt(accept a token replaced in the last few seconds, for flaky mobile networks). Rejected: it trades the one property that makes rotation worth having — a replayed token is proof of a leak — for a retry the client can do itself.
Consequences
- Every student story can now start from an empty database: register, sign in, use the product.
- Nothing proves an address belongs to the person who typed it. A stolen address cannot be recovered and a typo cannot be corrected by the user — both need an admin. Accepted, recorded here so it is not discovered during the defence.
- A forgotten password is an admin ticket. The admin module owes a reset route.
- Two password minimums live in the codebase on purpose.
PASSWORD_MIN_LENGTHis the one to use; the 8 inloginSchemais legacy tolerance and is commented as such. - The error envelope has one more optional field.
ApiErrorDoccarries it, and the OpenAPI drift guard intest/openapi.e2e-spec.tskeeps the two in step. AuditLogis written for the first time: registration, profile update and password change, withactiontaken fromAUDIT_ACTIONSinpackages/shared. A failed audit write is logged, never raised — the account really was created, and a 500 would say otherwise.- A password change signs the user out everywhere, including the tab they changed it in. The web client has to handle that; it is the behaviour users expect from a password change.