@shivaedev/identity 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.41.0 - 2026-11-21
4
+
5
+ ### Breaking
6
+
7
+ - The account preferences plugin moves to a browser-safe path and a new name. Replace `import { preferencesClient } from "@shivaedev/identity/server/better-auth/preferencesClient.ts"` with `import { preferencesPlugin } from "@shivaedev/identity/client/preferencesPlugin.ts"` and call `preferencesPlugin()` where you called `preferencesClient()`. Its header names come from `accountPreferenceHeaders` in `@shivaedev/identity/accountPreferenceHeaders.ts`.
8
+
3
9
  ## 0.40.0 - 2026-11-21
4
10
 
5
11
  ### Added
package/README.md CHANGED
@@ -145,16 +145,16 @@ export const preferencesModule = {
145
145
  } satisfies AppModule;
146
146
  ```
147
147
 
148
- To capture browser defaults, enable `{ accountPreferences: true }` in `betterAuthMount` and install the optional Better Auth client plugin:
148
+ To capture a client's defaults, enable `{ accountPreferences: true }` in `betterAuthMount` and install the Better Auth client plugin from `@shivaedev/identity/client/preferencesPlugin.ts`, which holds no server code:
149
149
 
150
150
  ```ts
151
151
  import { createAuthClient } from "better-auth/client";
152
- import { preferencesClient } from "@shivaedev/identity/server/better-auth/preferencesClient.ts";
152
+ import { preferencesPlugin } from "@shivaedev/identity/client/preferencesPlugin.ts";
153
153
 
154
- export const auth = createAuthClient({ plugins: [preferencesClient()] });
154
+ export const auth = createAuthClient({ plugins: [preferencesPlugin()] });
155
155
  ```
156
156
 
157
- The browser sends its `Intl.DateTimeFormat` timezone and locale to the auth mount. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the browser's first `getSession` captures them. Missing or invalid browser timezone data leaves preferences uncaptured; a later browser session can capture them. Other clients can call the `capture` contract with their own defaults.
157
+ The client sends its `Intl.DateTimeFormat` timezone and locale to the auth mount in the `x-platform-account-timezone` and `x-platform-account-locale` headers, whose names `accountPreferenceHeaders` from `@shivaedev/identity/accountPreferenceHeaders.ts` exports. It sends them only where a global `window` exists, as in a browser, a WebView or React Native, so a server-side auth call does not report the server's zone. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the client's first `getSession` captures them. Missing or invalid timezone data leaves preferences uncaptured; a later session can capture them. A bundled native shell installs the same plugin (see [Bundled native clients](#bundled-native-clients)). Clients without a Better Auth client can call the `capture` contract with their own defaults.
158
158
 
159
159
  `AccountClock` from `@shivaedev/identity/server/account-clock/service.ts` is a per-request service. Its Layer requires `Subject`, and its initializer captures that subject's saved timezone. Register that Layer in the host's `requestServices` slot and `accountPreferencesStore` in global `services`. Each new request sees the current saved timezone. Configure `AccountDayStart` from `@shivaedev/identity/server/account-clock/settings.ts` in minutes after local midnight; it defaults to zero and accepts integers from 0 through 1439. The same module exports `LogicalDay`.
160
160
 
@@ -559,16 +559,20 @@ export const secureCredential = Layer.succeed(SessionCredential, {
559
559
  });
560
560
  ```
561
561
 
562
- Pass that Layer to the Better Auth client as a plugin, and to `makeClient` through `storedCredential`:
562
+ Pass that Layer to the Better Auth client as a plugin, and to `makeClient` through `storedCredential`. When the mount captures [account preferences](#account-preferences-and-logical-days), install the same `preferencesPlugin()` the browser uses on the native auth client too, so the device's timezone and locale are captured at sign-in:
563
563
 
564
564
  ```ts
565
565
  import { createAuthClient } from "better-auth/client";
566
566
  import { Effect } from "effect";
567
567
  import { makeClient } from "@shivaedev/contract/makeClient.ts";
568
568
  import { sessionCredentialPlugin } from "@shivaedev/identity/client/adapters/sessionCredentialPlugin.ts";
569
+ import { preferencesPlugin } from "@shivaedev/identity/client/preferencesPlugin.ts";
569
570
  import { storedCredential } from "@shivaedev/identity/client/SessionCredential.ts";
570
571
 
571
- export const authClient = createAuthClient({ baseURL: publicOrigin, plugins: [sessionCredentialPlugin(secureCredential)] });
572
+ export const authClient = createAuthClient({
573
+ baseURL: publicOrigin,
574
+ plugins: [sessionCredentialPlugin(secureCredential), preferencesPlugin()],
575
+ });
572
576
  const client = makeClient(contracts, { bearerToken: Effect.provide(storedCredential, secureCredential), registry, url: `${publicOrigin}/rpc` });
573
577
  ```
574
578
 
@@ -578,7 +582,7 @@ Native sign-out revokes the stored session. Signing in again while sending the c
578
582
 
579
583
  Use `nativeOrigins` for bundled clients so their transport remains credential-free; other declared origins follow the sibling browser policy above.
580
584
 
581
- The host answers native preflights with POST for RPC, GET and POST for auth, and only `Authorization` and `Content-Type` headers. Native responses echo the allowed origin exactly with `Vary: Origin`; auth responses expose `set-auth-token`. Native responses never enable CORS credentials. It strips cookies from admitted native requests before auth or RPC session resolution, so only the signed bearer session can authenticate them. This prevents native access from opening a cookie CSRF path, even if a caller sends a cookie. Resource authorization remains app-owned.
585
+ The host answers native preflights with POST for RPC, GET and POST for auth. RPC allows only the `Authorization` and `Content-Type` headers; auth also allows the two account preference headers, for native and sibling browser origins alike. Native responses echo the allowed origin exactly with `Vary: Origin`; auth responses expose `set-auth-token`. Native responses never enable CORS credentials. It strips cookies from admitted native requests before auth or RPC session resolution, so only the signed bearer session can authenticate them. This prevents native access from opening a cookie CSRF path, even if a caller sends a cookie. Resource authorization remains app-owned.
582
586
 
583
587
  A WebView's live queries subscribe over the shared WebSocket client. `storedCredential` reads the port each time the socket connects: contract's `makeClient` sends the credential stored then as the socket's first frame, as the [contract guide](https://github.com/ShivaeDev/platform/blob/main/packages/contract/README.md#build-a-shared-websocket-client) describes, and connects without one when none is stored. A new client after each sign-in, sign-out or second sign-in, as React's `SessionBoundary` makes one per session, therefore carries the current credential. The host refuses a query's change stream over HTTP with `WebSocketRequired`. Over HTTP, use the WebView's own fetch with `credentials: "omit"` for commands, one-off reads and explicit NDJSON streams, and abort a stream's request to release server work; a buffering native HTTP bridge cannot deliver a stream incrementally. The host still validates trusted proxy peers and forwarded authority, enforces NDJSON and body limits, uses only transport credentials, redacts diagnostics and authorizes sessions. Native HTTP callers without an Origin can exercise bearer RPC with an origin policy that explicitly permits missing Origins.
584
588
 
@@ -0,0 +1,5 @@
1
+ export declare const accountPreferenceHeaders: {
2
+ readonly locale: "x-platform-account-locale";
3
+ readonly timezone: "x-platform-account-timezone";
4
+ };
5
+ //# sourceMappingURL=accountPreferenceHeaders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferenceHeaders.d.ts","sourceRoot":"","sources":["../src/accountPreferenceHeaders.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB;aACpC,MAAM,EAAE,2BAA2B;aACnC,QAAQ,EAAE,6BAA6B;CAC9B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const accountPreferenceHeaders = {
2
+ locale: "x-platform-account-locale",
3
+ timezone: "x-platform-account-timezone",
4
+ };
5
+ //# sourceMappingURL=accountPreferenceHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferenceHeaders.js","sourceRoot":"","sources":["../src/accountPreferenceHeaders.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,MAAM,EAAE,2BAA2B;IACnC,QAAQ,EAAE,6BAA6B;CAC9B,CAAC"}
@@ -0,0 +1,17 @@
1
+ interface PreferenceRequest {
2
+ readonly headers: Headers;
3
+ }
4
+ interface PreferenceFetchPlugin {
5
+ readonly hooks: {
6
+ readonly onRequest: (context: PreferenceRequest) => void;
7
+ };
8
+ readonly id: string;
9
+ readonly name: string;
10
+ }
11
+ export interface PreferencesPlugin {
12
+ readonly fetchPlugins: PreferenceFetchPlugin[];
13
+ readonly id: "identity-account-preferences";
14
+ }
15
+ export declare function preferencesPlugin(): PreferencesPlugin;
16
+ export {};
17
+ //# sourceMappingURL=preferencesPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preferencesPlugin.d.ts","sourceRoot":"","sources":["../../src/client/preferencesPlugin.ts"],"names":[],"mappings":"AAGA,UAAU,iBAAiB;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B;AAED,UAAU,qBAAqB;IAC9B,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAA;KAAE,CAAC;IAC7E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,YAAY,EAAE,qBAAqB,EAAE,CAAC;IAC/C,QAAQ,CAAC,EAAE,EAAE,8BAA8B,CAAC;CAC5C;AAED,wBAAgB,iBAAiB,IAAI,iBAAiB,CAqBrD"}
@@ -1,17 +1,17 @@
1
- export function preferencesClient() {
1
+ import { accountPreferenceHeaders } from "#accountPreferenceHeaders.ts";
2
+ export function preferencesPlugin() {
2
3
  return {
3
4
  fetchPlugins: [
4
5
  {
5
6
  hooks: {
6
7
  onRequest(context) {
8
+ // A server-rendered auth call would send the server's zone, so only a page or app shell sends one.
7
9
  if (!("window" in globalThis)) {
8
- return context;
10
+ return;
9
11
  }
10
12
  const { locale, timeZone } = new Intl.DateTimeFormat().resolvedOptions();
11
- const headers = new Headers(context.headers);
12
- headers.set("x-platform-account-timezone", timeZone);
13
- headers.set("x-platform-account-locale", locale);
14
- return { ...context, headers };
13
+ context.headers.set(accountPreferenceHeaders.timezone, timeZone);
14
+ context.headers.set(accountPreferenceHeaders.locale, locale);
15
15
  },
16
16
  },
17
17
  id: "identity-account-preferences",
@@ -21,4 +21,4 @@ export function preferencesClient() {
21
21
  id: "identity-account-preferences",
22
22
  };
23
23
  }
24
- //# sourceMappingURL=preferencesClient.js.map
24
+ //# sourceMappingURL=preferencesPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preferencesPlugin.js","sourceRoot":"","sources":["../../src/client/preferencesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAkBxE,MAAM,UAAU,iBAAiB;IAChC,OAAO;QACN,YAAY,EAAE;YACb;gBACC,KAAK,EAAE;oBACN,SAAS,CAAC,OAAO;wBAChB,mGAAmG;wBACnG,IAAI,CAAC,CAAC,QAAQ,IAAI,UAAU,CAAC,EAAE,CAAC;4BAC/B,OAAO;wBACR,CAAC;wBACD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC;wBACzE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;wBACjE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;oBAC9D,CAAC;iBACD;gBACD,EAAE,EAAE,8BAA8B;gBAClC,IAAI,EAAE,8BAA8B;aACpC;SACD;QACD,EAAE,EAAE,8BAA8B;KAClC,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"accountPreferenceOptions.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/accountPreferenceOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAIhD,eAAO,MAAM,wBAAwB,GAAgC,QAAQ,SAAS,iBAAiB;;;;;;;;;;wDA0BrG,CAAC"}
1
+ {"version":3,"file":"accountPreferenceOptions.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/accountPreferenceOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAKhD,eAAO,MAAM,wBAAwB,GAAgC,QAAQ,SAAS,iBAAiB;;;;;;;;;;wDA0BrG,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { createAuthMiddleware } from "better-auth/api";
2
2
  import { Effect, Option, Schema } from "effect";
3
+ import { accountPreferenceHeaders } from "#accountPreferenceHeaders.ts";
3
4
  import { AccountPreferenceValues } from "#accountPreferenceValues.ts";
4
5
  import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
5
6
  export const accountPreferenceOptions = Effect.fnUntraced(function* (options) {
@@ -8,8 +9,8 @@ export const accountPreferenceOptions = Effect.fnUntraced(function* (options) {
8
9
  const capture = createAuthMiddleware(async (context) => {
9
10
  const session = context.context.newSession ?? context.context.session;
10
11
  const values = Schema.decodeUnknownOption(AccountPreferenceValues)({
11
- locale: context.headers?.get("x-platform-account-locale"),
12
- timezone: context.headers?.get("x-platform-account-timezone"),
12
+ locale: context.headers?.get(accountPreferenceHeaders.locale),
13
+ timezone: context.headers?.get(accountPreferenceHeaders.timezone),
13
14
  units: "metric",
14
15
  });
15
16
  if (session !== null && session !== undefined && Option.isSome(values)) {
@@ -1 +1 @@
1
- {"version":3,"file":"accountPreferenceOptions.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/accountPreferenceOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAsC,OAAiB;IACzH,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,uBAAuB,CAAC;IAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAS,CAAC;IAChD,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,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,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1H,CAAC;IACF,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG;QACd,KAAK,EAAE;YACN,KAAK,EAAE;gBACN;oBACC,OAAO,EAAE,OAAO;oBAChB,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC;iBAC1I;aACD;SACD;QACD,EAAE,EAAE,8BAA8B;KACP,CAAC;IAC7B,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAA8B,CAAC;AAClG,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/identity",
3
- "version": "0.40.0",
3
+ "version": "0.41.0",
4
4
  "description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
5
5
  "keywords": [
6
6
  "effect"
@@ -58,11 +58,11 @@
58
58
  "@better-auth/oauth-provider": "1.7.23",
59
59
  "@effect/platform-node": "4.1.4",
60
60
  "@effect/sql-pg": "4.1.4",
61
- "@shivaedev/admin": "0.29.2",
62
- "@shivaedev/build": "0.7.1",
63
- "@shivaedev/quality": "0.83.4",
64
- "@shivaedev/server": "0.43.0",
65
- "@shivaedev/test-kits": "0.16.5",
61
+ "@shivaedev/admin": "0.29.3",
62
+ "@shivaedev/build": "0.8.0",
63
+ "@shivaedev/quality": "0.84.0",
64
+ "@shivaedev/server": "0.44.0",
65
+ "@shivaedev/test-kits": "0.16.6",
66
66
  "@shivaedev/test-sql": "0.26.1",
67
67
  "@shivaedev/test-story": "0.52.5",
68
68
  "@types/node": "24.19.2",
@@ -0,0 +1,4 @@
1
+ export const accountPreferenceHeaders = {
2
+ locale: "x-platform-account-locale",
3
+ timezone: "x-platform-account-timezone",
4
+ } as const;
@@ -0,0 +1,40 @@
1
+ import { accountPreferenceHeaders } from "#accountPreferenceHeaders.ts";
2
+
3
+ // Structural copies of the Better Auth client plugin shapes: the client core must not reach the optional better-auth peer.
4
+ interface PreferenceRequest {
5
+ readonly headers: Headers;
6
+ }
7
+
8
+ interface PreferenceFetchPlugin {
9
+ readonly hooks: { readonly onRequest: (context: PreferenceRequest) => void };
10
+ readonly id: string;
11
+ readonly name: string;
12
+ }
13
+
14
+ export interface PreferencesPlugin {
15
+ readonly fetchPlugins: PreferenceFetchPlugin[];
16
+ readonly id: "identity-account-preferences";
17
+ }
18
+
19
+ export function preferencesPlugin(): PreferencesPlugin {
20
+ return {
21
+ fetchPlugins: [
22
+ {
23
+ hooks: {
24
+ onRequest(context) {
25
+ // A server-rendered auth call would send the server's zone, so only a page or app shell sends one.
26
+ if (!("window" in globalThis)) {
27
+ return;
28
+ }
29
+ const { locale, timeZone } = new Intl.DateTimeFormat().resolvedOptions();
30
+ context.headers.set(accountPreferenceHeaders.timezone, timeZone);
31
+ context.headers.set(accountPreferenceHeaders.locale, locale);
32
+ },
33
+ },
34
+ id: "identity-account-preferences",
35
+ name: "identity-account-preferences",
36
+ },
37
+ ],
38
+ id: "identity-account-preferences",
39
+ };
40
+ }
@@ -1,6 +1,7 @@
1
1
  import type { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
2
2
  import { createAuthMiddleware } from "better-auth/api";
3
3
  import { Effect, Option, Schema } from "effect";
4
+ import { accountPreferenceHeaders } from "#accountPreferenceHeaders.ts";
4
5
  import { AccountPreferenceValues } from "#accountPreferenceValues.ts";
5
6
  import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
6
7
 
@@ -10,8 +11,8 @@ export const accountPreferenceOptions = Effect.fnUntraced(function* <TOptions ex
10
11
  const capture = createAuthMiddleware(async (context) => {
11
12
  const session = context.context.newSession ?? context.context.session;
12
13
  const values = Schema.decodeUnknownOption(AccountPreferenceValues)({
13
- locale: context.headers?.get("x-platform-account-locale"),
14
- timezone: context.headers?.get("x-platform-account-timezone"),
14
+ locale: context.headers?.get(accountPreferenceHeaders.locale),
15
+ timezone: context.headers?.get(accountPreferenceHeaders.timezone),
15
16
  units: "metric",
16
17
  });
17
18
  if (session !== null && session !== undefined && Option.isSome(values)) {
@@ -1,3 +0,0 @@
1
- import type { BetterAuthClientPlugin } from "better-auth/client";
2
- export declare function preferencesClient(): Pick<BetterAuthClientPlugin, "id" | "fetchPlugins">;
3
- //# sourceMappingURL=preferencesClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preferencesClient.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/preferencesClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,wBAAgB,iBAAiB,IAAI,IAAI,CAAC,sBAAsB,EAAE,IAAI,GAAG,cAAc,CAAC,CAsBvF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"preferencesClient.js","sourceRoot":"","sources":["../../../src/server/better-auth/preferencesClient.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB;IAChC,OAAO;QACN,YAAY,EAAE;YACb;gBACC,KAAK,EAAE;oBACN,SAAS,CAAC,OAAO;wBAChB,IAAI,CAAC,CAAC,QAAQ,IAAI,UAAU,CAAC,EAAE,CAAC;4BAC/B,OAAO,OAAO,CAAC;wBAChB,CAAC;wBACD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC;wBACzE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;wBAC7C,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,QAAQ,CAAC,CAAC;wBACrD,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;wBACjD,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;oBAChC,CAAC;iBACD;gBACD,EAAE,EAAE,8BAA8B;gBAClC,IAAI,EAAE,8BAA8B;aACpC;SACD;QACD,EAAE,EAAE,8BAA8B;KAClC,CAAC;AACH,CAAC"}
@@ -1,25 +0,0 @@
1
- import type { BetterAuthClientPlugin } from "better-auth/client";
2
-
3
- export function preferencesClient(): Pick<BetterAuthClientPlugin, "id" | "fetchPlugins"> {
4
- return {
5
- fetchPlugins: [
6
- {
7
- hooks: {
8
- onRequest(context) {
9
- if (!("window" in globalThis)) {
10
- return context;
11
- }
12
- const { locale, timeZone } = new Intl.DateTimeFormat().resolvedOptions();
13
- const headers = new Headers(context.headers);
14
- headers.set("x-platform-account-timezone", timeZone);
15
- headers.set("x-platform-account-locale", locale);
16
- return { ...context, headers };
17
- },
18
- },
19
- id: "identity-account-preferences",
20
- name: "identity-account-preferences",
21
- },
22
- ],
23
- id: "identity-account-preferences",
24
- };
25
- }