mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
fix(api): give the generic auth refusals a stable errorCode
`requireAuth`, `requireAdmin`, `requireCookieAuth`, `requireFreshMfa` and `requireBearerAuth` all refused with a bare prose string and no `meta`. So the single most important branch a native client makes — refresh the token and retry, drop the session and show the login screen, or stop retrying because this credential will never work — could only be made by string-matching the English sentence "Token expired". Any rewording of that string, or a localisation pass, silently turns a recoverable refresh into a forced logout for every already-shipped build. The mechanism was already here and these gates were the ones skipped: the assistant, consent, step-up, module and sharing refusals all carry `meta.errorCode`, and `/api/auth/refresh` emits `auth.refresh.*`. So `HttpError` takes an optional code and the wrapper puts it in the same field. Five values, dot.case like the majority: `auth.missing`, `auth.token.expired`, `auth.token.invalid`, `auth.scope.insufficient`, `auth.admin.required`. A revoked token reads invalid, not expired — refreshing a revoked token loops forever. Additive: an HttpError thrown without a code serialises byte-identically to before, which is most of them. The published 401 description now enumerates the codes and says what a client should do with each.
This commit is contained in:
1 parent
a7bdf14a4e
commit
21dd7c7e48
5 files changed
+322
-15
No files matched your search
@@ -70,7 +70,13 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/CycleCustomSymptomListEnvelope"
|
||||
"401": &a1
|
||||
description: Authentication required or invalid credentials.
|
||||
description: "Authentication required or invalid credentials. `meta.errorCode` says which, and it is the field to branch
|
||||
on — the English sentence beside it may be reworded or localised at any time. `auth.missing`: no session
|
||||
cookie and no Bearer header; send the user to sign in. `auth.token.expired`: the Bearer token's lifetime has
|
||||
passed; refresh and retry the request. `auth.token.invalid`: unknown, revoked, or the owning account is
|
||||
gone; discard the credential and sign in again — retrying will not help. The related 403 refusals carry
|
||||
`auth.scope.insufficient` (the credential is valid but its scope does not reach this route, including any
|
||||
Bearer token against an admin surface) and `auth.admin.required` (a cookie session that is not an admin's)."
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
|
||||
Reference in new issue
Block a user