Skip to content

Commit 00c32f2

Browse files
xuyushun441-sysos-zhuangclaude
authored
feat(server): GET /auth/me/localization — tenant regional defaults for every user (#2122)
Phase 2a of unifying currency. The `localization` settings (currency/locale/ timezone) are gated to `setup.access`, and `discovery` is static/context-free — so a regular user's client has no way to learn the tenant's default currency or locale to format values consistently. This adds `GET /api/v1/auth/me/localization`, returning the resolved `{ currency, locale, timezone }` off the request ExecutionContext (the same values #2119 wired in) to every AUTHENTICATED user — without the setup.access gate on the underlying settings. A thin passthrough of `resolveCtx(c)`; the ctx resolution itself is covered by resolve-execution-context tests. Unblocks the objectui client (Phase 2): a LocalizationProvider can fetch this once and feed a single currency/number formatter the tenant default + locale, replacing ~20 ad-hoc per-site currency-resolution paths. Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 70609af commit 00c32f2

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/plugin-hono-server": minor
3+
---
4+
5+
Expose resolved regional defaults to every authenticated user.
6+
7+
Adds `GET /api/v1/auth/me/localization` returning the request tenant's resolved
8+
`{ currency, locale, timezone }` from the ExecutionContext (ADR-0053). The
9+
`localization` SETTINGS are gated to `setup.access`, but the resolved defaults
10+
are needed by every renderer to format currency/dates/numbers — so they are
11+
surfaced here without that gate. Enables a client to format a currency field
12+
in the tenant's default currency when the field omits its own.

packages/plugins/plugin-hono-server/src/hono-plugin.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,25 @@ export class HonoServerPlugin implements Plugin {
718718
}
719719
});
720720

721+
// GET /me/localization — the resolved regional defaults (currency /
722+
// locale / timezone) for the current request's tenant, exposed to EVERY
723+
// authenticated user. The `localization` SETTINGS are gated to
724+
// `setup.access`, but the resolved defaults are needed by every renderer
725+
// to format currency/dates/numbers — so they ride on the request
726+
// ExecutionContext (ADR-0053) and are surfaced here without that gate.
727+
rawApp.get(`${prefix}/auth/me/localization`, async (c: any) => {
728+
const execCtx = await resolveCtx(c);
729+
if (!execCtx?.userId) {
730+
return c.json({ authenticated: false });
731+
}
732+
return c.json({
733+
authenticated: true,
734+
currency: execCtx.currency ?? null,
735+
locale: execCtx.locale ?? null,
736+
timezone: execCtx.timezone ?? null,
737+
});
738+
});
739+
721740
// GET /me/apps — list apps the current user is allowed to enter.
722741
// Filters `metadata.list('app')` by:
723742
// 1. AppSchema.requiredPermissions ⊆ ctx.systemPermissions

0 commit comments

Comments
 (0)