@better-auth/expo 1.7.0-beta.2 → 1.7.0-beta.4
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 +15 -2
- package/dist/client.js +51 -10
- package/dist/index.js +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/{version-C8sKtO-X.js → version-DPtU3iXk.js} +1 -1
- package/package.json +5 -5
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) =>
|
|
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
|
-
|
|
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";
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-DPtU3iXk.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
|
-
|
|
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
|
-
|
|
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-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-DPtU3iXk.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";
|
package/dist/plugins/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/expo",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.4",
|
|
4
4
|
"description": "Better Auth integration for Expo and React Native applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,16 +70,16 @@
|
|
|
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.
|
|
74
|
-
"better-auth": "1.7.0-beta.
|
|
73
|
+
"@better-auth/core": "1.7.0-beta.4",
|
|
74
|
+
"better-auth": "1.7.0-beta.4"
|
|
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.
|
|
82
|
-
"better-auth": "^1.7.0-beta.
|
|
81
|
+
"@better-auth/core": "^1.7.0-beta.4",
|
|
82
|
+
"better-auth": "^1.7.0-beta.4"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|
|
85
85
|
"expo-constants": {
|