@better-auth/expo 1.6.15 → 1.6.17

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
@@ -132,11 +132,6 @@ declare const expoClient: (opts: ExpoClientOptions) => {
132
132
  init(url: string, options: ({
133
133
  priority?: RequestPriority | undefined;
134
134
  method?: string | undefined;
135
- headers?: (HeadersInit & (HeadersInit | {
136
- accept: "application/json" | "text/plain" | "application/octet-stream";
137
- "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
138
- authorization: "Bearer" | "Basic";
139
- })) | undefined;
140
135
  redirect?: RequestRedirect | undefined;
141
136
  window?: null | undefined;
142
137
  cache?: RequestCache | undefined;
@@ -172,6 +167,12 @@ declare const expoClient: (opts: ExpoClientOptions) => {
172
167
  prefix: string | (() => string | undefined) | undefined;
173
168
  value: string | (() => string | undefined) | undefined;
174
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;
175
176
  body?: any;
176
177
  query?: any;
177
178
  params?: any;
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-CdUF4nQi.js";
1
+ import { t as PACKAGE_VERSION } from "./version-FMOwlXga.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";
@@ -254,6 +254,16 @@ const expoClient = (opts) => {
254
254
  const storage = storageAdapter(opts?.storage);
255
255
  const isWeb = Platform.OS === "web";
256
256
  const cookiePrefix = opts?.cookiePrefix || "better-auth";
257
+ const clearSessionCache = async () => {
258
+ await storage.setItem(cookieName, "{}");
259
+ store?.atoms.session?.set({
260
+ ...store.atoms.session.get(),
261
+ data: null,
262
+ error: null,
263
+ isPending: false
264
+ });
265
+ await storage.setItem(localCacheName, "{}");
266
+ };
257
267
  const rawScheme = opts?.scheme || Constants.expoConfig?.scheme || Constants.platform?.scheme;
258
268
  const scheme = Array.isArray(rawScheme) ? rawScheme[0] : rawScheme;
259
269
  if (!scheme && !isWeb) throw new Error("Scheme not found in app.json. Please provide a scheme in the options.");
@@ -298,6 +308,7 @@ const expoClient = (opts) => {
298
308
  const data = context.data;
299
309
  await storage.setItem(localCacheName, JSON.stringify(data));
300
310
  }
311
+ if (context.request.url.toString().includes("/sign-out")) await clearSessionCache();
301
312
  if (context.data?.redirect && (context.request.url.toString().includes("/sign-in") || context.request.url.toString().includes("/link-social")) && !context.request?.body.includes("idToken")) {
302
313
  const to = JSON.parse(context.request.body)?.callbackURL;
303
314
  const signInURL = context.data?.url;
@@ -334,11 +345,14 @@ const expoClient = (opts) => {
334
345
  };
335
346
  options = options || {};
336
347
  options.credentials = "omit";
337
- if (options.body?.idToken !== void 0) options.headers = {
338
- ...options.headers,
339
- "x-skip-oauth-proxy": "true"
340
- };
341
- else {
348
+ if (options.body?.idToken !== void 0) {
349
+ const cookie = url.includes("/link-social") ? getCookie(storage.getItem(cookieName) || "{}") : "";
350
+ options.headers = {
351
+ ...options.headers,
352
+ ...cookie ? { cookie } : {},
353
+ "x-skip-oauth-proxy": "true"
354
+ };
355
+ } else {
342
356
  const cookie = getCookie(storage.getItem(cookieName) || "{}");
343
357
  options.headers = {
344
358
  ...options.headers,
@@ -364,16 +378,7 @@ const expoClient = (opts) => {
364
378
  options.body.errorCallbackURL = url;
365
379
  }
366
380
  }
367
- if (url.includes("/sign-out")) {
368
- await storage.setItem(cookieName, "{}");
369
- store?.atoms.session?.set({
370
- ...store.atoms.session.get(),
371
- data: null,
372
- error: null,
373
- isPending: false
374
- });
375
- await storage.setItem(localCacheName, "{}");
376
- }
381
+ if (url.includes("/sign-out")) await clearSessionCache();
377
382
  }
378
383
  return {
379
384
  url,
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-CdUF4nQi.js";
1
+ import { t as PACKAGE_VERSION } from "./version-FMOwlXga.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";
@@ -12,14 +12,22 @@ const expoAuthorizationProxy = createAuthEndpoint("/expo-authorization-proxy", {
12
12
  }),
13
13
  metadata: HIDE_METADATA
14
14
  }, async (ctx) => {
15
+ const { authorizationURL } = ctx.query;
16
+ if (authorizationURL.includes("#")) throw new APIError("BAD_REQUEST", { message: "Invalid authorizationURL" });
17
+ let url;
18
+ try {
19
+ url = new URL(authorizationURL);
20
+ } catch {
21
+ throw new APIError("BAD_REQUEST", { message: "Invalid authorizationURL" });
22
+ }
23
+ if (url.protocol !== "https:" || url.origin === new URL(ctx.context.baseURL).origin) throw new APIError("BAD_REQUEST", { message: "Invalid authorizationURL" });
15
24
  const { oauthState } = ctx.query;
16
25
  if (oauthState) {
17
26
  const oauthStateCookie = ctx.context.createAuthCookie("oauth_state", { maxAge: 600 });
18
27
  ctx.setCookie(oauthStateCookie.name, oauthState, oauthStateCookie.attributes);
19
- return ctx.redirect(ctx.query.authorizationURL);
28
+ return ctx.redirect(authorizationURL);
20
29
  }
21
- const { authorizationURL } = ctx.query;
22
- const state = new URL(authorizationURL).searchParams.get("state");
30
+ const state = url.searchParams.get("state");
23
31
  if (!state) throw new APIError("BAD_REQUEST", { message: "Unexpected error" });
24
32
  const stateCookie = ctx.context.createAuthCookie("state", { maxAge: 300 });
25
33
  await ctx.setSignedCookie(stateCookie.name, state, ctx.context.secret, stateCookie.attributes);
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "../version-CdUF4nQi.js";
1
+ import { t as PACKAGE_VERSION } from "../version-FMOwlXga.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.6.15";
3
+ const PACKAGE_VERSION = "1.6.17";
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.6.15",
3
+ "version": "1.6.17",
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.3.0",
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.3.0",
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.6.15",
74
- "better-auth": "1.6.15"
73
+ "@better-auth/core": "1.6.17",
74
+ "better-auth": "1.6.17"
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.6.15",
82
- "better-auth": "^1.6.15"
81
+ "@better-auth/core": "^1.6.17",
82
+ "better-auth": "^1.6.17"
83
83
  },
84
84
  "peerDependenciesMeta": {
85
85
  "expo-constants": {