@better-auth/expo 1.7.0-beta.3 → 1.7.0-beta.5

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/dist/client.d.ts CHANGED
@@ -84,10 +84,23 @@ declare function hasBetterAuthCookies(setCookieHeader: string, cookiePrefix: str
84
84
  declare function normalizeCookieName(name: string): string;
85
85
  declare function storageAdapter(storage: {
86
86
  getItem: (name: string) => string | null;
87
- setItem: (name: string, value: string) => void;
87
+ setItem: (name: string, value: string) => unknown;
88
88
  }): {
89
+ /**
90
+ * Reads a value, reassembling it if it was split across chunk keys. A value
91
+ * that fit is returned as-is (values written before chunking still read
92
+ * back); a missing chunk returns `null` so a torn write fails closed.
93
+ */
89
94
  getItem: (name: string) => string | null;
90
- setItem: (name: string, value: string) => void;
95
+ /**
96
+ * Stores `value`, splitting it across chunk keys when it exceeds the
97
+ * per-write limit. The base key is cleared before the chunks are rewritten
98
+ * and set to the marker last, as the commit point, so a write interrupted
99
+ * partway through reads as absent rather than a mix of old and new chunks.
100
+ * Failures are logged, not thrown: persistence is best-effort and must not
101
+ * break the request.
102
+ */
103
+ setItem: (name: string, value: string) => Promise<void>;
91
104
  };
92
105
  declare const expoClient: (opts: ExpoClientOptions) => {
93
106
  id: "expo";
@@ -119,11 +132,6 @@ declare const expoClient: (opts: ExpoClientOptions) => {
119
132
  init(url: string, options: ({
120
133
  priority?: RequestPriority | undefined;
121
134
  method?: string | undefined;
122
- headers?: (HeadersInit & (HeadersInit | {
123
- accept: "application/json" | "text/plain" | "application/octet-stream";
124
- "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
125
- authorization: "Bearer" | "Basic";
126
- })) | undefined;
127
135
  redirect?: RequestRedirect | undefined;
128
136
  window?: null | undefined;
129
137
  cache?: RequestCache | undefined;
@@ -159,6 +167,12 @@ declare const expoClient: (opts: ExpoClientOptions) => {
159
167
  prefix: string | (() => string | undefined) | undefined;
160
168
  value: string | (() => string | undefined) | undefined;
161
169
  }) | undefined;
170
+ headers?: {} | {
171
+ [x: string]: string | undefined;
172
+ accept?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream") | undefined;
173
+ "content-type"?: ((string & {}) | "application/json" | "text/plain" | "application/octet-stream" | "application/x-www-form-urlencoded" | "multipart/form-data") | undefined;
174
+ authorization?: ((string & {}) | `Bearer ${string}` | `Basic ${string}`) | undefined;
175
+ } | undefined;
162
176
  body?: any;
163
177
  query?: any;
164
178
  params?: any;
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-CdCucTCM.js";
1
+ import { t as PACKAGE_VERSION } from "./version-B5BVt-3D.js";
2
2
  import { safeJSONParse } from "@better-auth/core/utils/json";
3
3
  import { SECURE_COOKIE_PREFIX, parseSetCookieHeader, parseSetCookieHeader as parseSetCookieHeader$1, stripSecureCookiePrefix } from "better-auth/cookies";
4
4
  import Constants from "expo-constants";
@@ -195,13 +195,54 @@ function hasBetterAuthCookies(setCookieHeader, cookiePrefix) {
195
195
  function normalizeCookieName(name) {
196
196
  return name.replace(/:/g, "_");
197
197
  }
198
+ /**
199
+ * Max characters written per `setItem`. Native secure stores silently reject
200
+ * oversized writes (iOS Keychain refuses values above ~2KB), losing the cookie,
201
+ * so a larger value is split across keys here. Mirrors the server's
202
+ * `chunkCookie`/`joinChunks` in `session-store.ts`; keep the two in sync.
203
+ *
204
+ * @see https://github.com/better-auth/better-auth/issues/9151
205
+ */
206
+ const STORAGE_VALUE_LIMIT = 1800;
207
+ /**
208
+ * Marks a base key whose value is split across `<key>.0..N` chunks. The leading
209
+ * control char can't start a JSON value (so it never collides) and, unlike NUL,
210
+ * survives the native storage bridge without C-string truncation.
211
+ */
212
+ const CHUNK_MARKER = "ba-chunks:";
198
213
  function storageAdapter(storage) {
199
214
  return {
200
215
  getItem: (name) => {
201
- return storage.getItem(normalizeCookieName(name));
216
+ const key = normalizeCookieName(name);
217
+ const stored = storage.getItem(key);
218
+ if (stored == null || !stored.startsWith(CHUNK_MARKER)) return stored;
219
+ const count = Number(stored.slice(11));
220
+ if (!Number.isInteger(count) || count < 1) return null;
221
+ let value = "";
222
+ for (let i = 0; i < count; i++) {
223
+ const chunk = storage.getItem(`${key}.${i}`);
224
+ if (chunk == null) return null;
225
+ value += chunk;
226
+ }
227
+ return value;
202
228
  },
203
- setItem: (name, value) => {
204
- return storage.setItem(normalizeCookieName(name), value);
229
+ setItem: async (name, value) => {
230
+ const key = normalizeCookieName(name);
231
+ try {
232
+ if (value.length <= STORAGE_VALUE_LIMIT) {
233
+ await storage.setItem(key, value);
234
+ return;
235
+ }
236
+ await storage.setItem(key, "");
237
+ const count = Math.ceil(value.length / STORAGE_VALUE_LIMIT);
238
+ for (let i = 0; i < count; i++) {
239
+ const start = i * STORAGE_VALUE_LIMIT;
240
+ await storage.setItem(`${key}.${i}`, value.slice(start, start + STORAGE_VALUE_LIMIT));
241
+ }
242
+ await storage.setItem(key, `${CHUNK_MARKER}${count}`);
243
+ } catch (error) {
244
+ console.error(`[better-auth/expo] failed to persist "${key}" to storage`, error);
245
+ }
205
246
  }
206
247
  };
207
248
  }
@@ -248,14 +289,14 @@ const expoClient = (opts) => {
248
289
  const prevCookie = storage.getItem(cookieName);
249
290
  const toSetCookie = getSetCookie(setCookie || "", prevCookie ?? void 0);
250
291
  if (hasSessionCookieChanged(prevCookie, toSetCookie)) {
251
- storage.setItem(cookieName, toSetCookie);
292
+ await storage.setItem(cookieName, toSetCookie);
252
293
  store?.notify("$sessionSignal");
253
- } else storage.setItem(cookieName, toSetCookie);
294
+ } else await storage.setItem(cookieName, toSetCookie);
254
295
  }
255
296
  }
256
297
  if (context.request.url.toString().includes("/get-session") && !opts?.disableCache) {
257
298
  const data = context.data;
258
- storage.setItem(localCacheName, JSON.stringify(data));
299
+ await storage.setItem(localCacheName, JSON.stringify(data));
259
300
  }
260
301
  if (context.data?.redirect && (context.request.url.toString().includes("/sign-in") || context.request.url.toString().includes("/link-social")) && !context.request?.body.includes("idToken")) {
261
302
  const to = JSON.parse(context.request.body)?.callbackURL;
@@ -282,7 +323,7 @@ const expoClient = (opts) => {
282
323
  const cookie = new URL(result.url).searchParams.get("cookie");
283
324
  if (!cookie) return;
284
325
  const toSetCookie = getSetCookie(cookie, storage.getItem(cookieName) ?? void 0);
285
- storage.setItem(cookieName, toSetCookie);
326
+ await storage.setItem(cookieName, toSetCookie);
286
327
  store?.notify("$sessionSignal");
287
328
  }
288
329
  } },
@@ -324,14 +365,14 @@ const expoClient = (opts) => {
324
365
  }
325
366
  }
326
367
  if (url.includes("/sign-out")) {
327
- storage.setItem(cookieName, "{}");
368
+ await storage.setItem(cookieName, "{}");
328
369
  store?.atoms.session?.set({
329
370
  ...store.atoms.session.get(),
330
371
  data: null,
331
372
  error: null,
332
373
  isPending: false
333
374
  });
334
- storage.setItem(localCacheName, "{}");
375
+ await storage.setItem(localCacheName, "{}");
335
376
  }
336
377
  }
337
378
  return {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-CdCucTCM.js";
1
+ import { t as PACKAGE_VERSION } from "./version-B5BVt-3D.js";
2
2
  import { createAuthMiddleware } from "@better-auth/core/api";
3
3
  import { HIDE_METADATA } from "better-auth";
4
4
  import { APIError, createAuthEndpoint } from "better-auth/api";
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "../version-CdCucTCM.js";
1
+ import { t as PACKAGE_VERSION } from "../version-B5BVt-3D.js";
2
2
  //#region src/plugins/last-login-method.ts
3
3
  const paths = [
4
4
  "/callback/",
@@ -1,5 +1,5 @@
1
1
  //#endregion
2
2
  //#region src/version.ts
3
- const PACKAGE_VERSION = "1.7.0-beta.3";
3
+ const PACKAGE_VERSION = "1.7.0-beta.5";
4
4
  //#endregion
5
5
  export { PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/expo",
3
- "version": "1.7.0-beta.3",
3
+ "version": "1.7.0-beta.5",
4
4
  "description": "Better Auth integration for Expo and React Native applications.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,28 +58,28 @@
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
- "@better-fetch/fetch": "1.1.21",
62
- "better-call": "1.3.5",
61
+ "@better-fetch/fetch": "1.2.2",
62
+ "better-call": "1.3.6",
63
63
  "zod": "^4.3.6"
64
64
  },
65
65
  "devDependencies": {
66
- "@better-fetch/fetch": "1.1.21",
66
+ "@better-fetch/fetch": "1.2.2",
67
67
  "expo-constants": "~55.0.7",
68
68
  "expo-linking": "~55.0.7",
69
69
  "expo-network": "~55.0.8",
70
70
  "expo-web-browser": "~55.0.9",
71
71
  "react-native": "~0.84.1",
72
72
  "tsdown": "0.21.1",
73
- "@better-auth/core": "1.7.0-beta.3",
74
- "better-auth": "1.7.0-beta.3"
73
+ "@better-auth/core": "1.7.0-beta.5",
74
+ "better-auth": "1.7.0-beta.5"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "expo-constants": ">=17.0.0",
78
78
  "expo-linking": ">=7.0.0",
79
79
  "expo-network": ">=8.0.7",
80
80
  "expo-web-browser": ">=14.0.0",
81
- "@better-auth/core": "^1.7.0-beta.3",
82
- "better-auth": "^1.7.0-beta.3"
81
+ "@better-auth/core": "^1.7.0-beta.5",
82
+ "better-auth": "^1.7.0-beta.5"
83
83
  },
84
84
  "peerDependenciesMeta": {
85
85
  "expo-constants": {