User locale
In plain words
Section titled “In plain words”The browser sends its current language with each request. The server exposes
the resolved language as ctx.locale and stores a user’s chosen locale in the
session at login. Magic-link email can use that value for translated text and
locale-specific URLs. If no valid request or session locale exists, the app’s
boot default applies, then English.
1. Browser → server (X-Locale)
Section titled “1. Browser → server (X-Locale)”- The client sends
document.documentElement.langas anX-Localeheader. The server usesAccept-Languagewhen that header is absent or invalid. - The server exposes it as an always-present
ctx.locale; handlers can answer locale-dependently and derive mail locales from it.
2. Session persistence (SessionUser.locale in the JWT)
Section titled “2. Session persistence (SessionUser.locale in the JWT)”- The user’s chosen locale is written into the JWT at login (
localeclaim) and threaded through login / invite-accept / MFA handlers. SessionUser.localesurvives requests made without a browser locale signal. Work that explicitly carries that user can use the same value.ctx.localefalls back from the liveX-Localesignal toSessionUser.locale, keeping a consistent locale even when a request carries no browser locale.
3. Localized magic-link mails
Section titled “3. Localized magic-link mails”All auth mails (signup, password-reset, email-verification, invite, account-unlock) render in the requester’s locale:
appUrlmay be a function(locale) => stringto build locale-aware landing paths (e.g./de/...).- Mails derive the locale from
ctx.locale/SessionUser.locale, never a hard-coded server default.
Rule of thumb
Section titled “Rule of thumb”- New outbound mails: always derive locale from
ctx.locale(fallbackSessionUser.locale), never hard-code a server default. - Use
appUrlas(locale) => stringwhen the landing path is locale-sensitive.
See also
Section titled “See also”- Field formatting, locale-aware display rules.
- Auth and permissions, what the session carries besides locale.