@better-auth/expo 1.4.12 → 1.4.13

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.mts CHANGED
@@ -133,6 +133,7 @@ declare const expoClient: (opts: ExpoClientOptions) => {
133
133
  authorization: "Bearer" | "Basic";
134
134
  })) | undefined;
135
135
  redirect?: RequestRedirect | undefined;
136
+ window?: null | undefined;
136
137
  cache?: RequestCache | undefined;
137
138
  credentials?: RequestCredentials | undefined;
138
139
  integrity?: string | undefined;
@@ -142,7 +143,6 @@ declare const expoClient: (opts: ExpoClientOptions) => {
142
143
  referrer?: string | undefined;
143
144
  referrerPolicy?: ReferrerPolicy | undefined;
144
145
  signal?: (AbortSignal | null) | undefined;
145
- window?: null | undefined;
146
146
  onRequest?: (<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>) => Promise<_better_fetch_fetch0.RequestContext | void> | _better_fetch_fetch0.RequestContext | void) | undefined;
147
147
  onResponse?: ((context: _better_fetch_fetch0.ResponseContext) => Promise<Response | void | _better_fetch_fetch0.ResponseContext> | Response | _better_fetch_fetch0.ResponseContext | void) | undefined;
148
148
  onSuccess?: ((context: _better_fetch_fetch0.SuccessContext<any>) => Promise<void> | void) | undefined;
package/dist/client.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { safeJSONParse } from "@better-auth/core/utils";
2
+ import { SECURE_COOKIE_PREFIX, stripSecureCookiePrefix } from "better-auth/cookies";
1
3
  import Constants from "expo-constants";
2
4
  import * as Linking from "expo-linking";
3
5
  import { AppState, Platform } from "react-native";
@@ -149,6 +151,20 @@ function getCookie(cookie) {
149
151
  return `${acc}; ${key}=${value.value}`;
150
152
  }, "");
151
153
  }
154
+ function getOAuthStateValue(cookieJson, cookiePrefix) {
155
+ if (!cookieJson) return null;
156
+ const parsed = safeJSONParse(cookieJson);
157
+ if (!parsed) return null;
158
+ const prefixes = Array.isArray(cookiePrefix) ? cookiePrefix : [cookiePrefix];
159
+ for (const prefix of prefixes) {
160
+ const candidates = [`${SECURE_COOKIE_PREFIX}${prefix}.oauth_state`, `${prefix}.oauth_state`];
161
+ for (const name of candidates) {
162
+ const value = parsed?.[name]?.value;
163
+ if (value) return value;
164
+ }
165
+ }
166
+ return null;
167
+ }
152
168
  function getOrigin(scheme) {
153
169
  return Linking.createURL("", { scheme });
154
170
  }
@@ -198,7 +214,7 @@ function hasBetterAuthCookies(setCookieHeader, cookiePrefix) {
198
214
  const cookieSuffixes = ["session_token", "session_data"];
199
215
  const prefixes = Array.isArray(cookiePrefix) ? cookiePrefix : [cookiePrefix];
200
216
  for (const name of cookies.keys()) {
201
- const nameWithoutSecure = name.startsWith("__Secure-") ? name.slice(9) : name;
217
+ const nameWithoutSecure = stripSecureCookiePrefix(name);
202
218
  for (const prefix of prefixes) if (prefix) {
203
219
  if (nameWithoutSecure.startsWith(prefix)) return true;
204
220
  } else for (const suffix of cookieSuffixes) if (nameWithoutSecure.endsWith(suffix)) return true;
@@ -278,7 +294,10 @@ const expoClient = (opts) => {
278
294
  if (Platform.OS === "android") try {
279
295
  Browser.dismissAuthSession();
280
296
  } catch {}
281
- const proxyURL = `${context.request.baseURL}/expo-authorization-proxy?authorizationURL=${encodeURIComponent(signInURL)}`;
297
+ const oauthStateValue = getOAuthStateValue(await storage.getItem(cookieName), cookiePrefix);
298
+ const params = new URLSearchParams({ authorizationURL: signInURL });
299
+ if (oauthStateValue) params.append("oauthState", oauthStateValue);
300
+ const proxyURL = `${context.request.baseURL}/expo-authorization-proxy?${params.toString()}`;
282
301
  const result = await Browser.openAuthSessionAsync(proxyURL, to, opts?.webBrowserOptions);
283
302
  if (result.type !== "success") return;
284
303
  const url = new URL(result.url);
package/dist/index.d.mts CHANGED
@@ -31,6 +31,7 @@ declare const expo: (options?: ExpoOptions | undefined) => {
31
31
  method: "GET";
32
32
  query: zod0.ZodObject<{
33
33
  authorizationURL: zod0.ZodString;
34
+ oauthState: zod0.ZodOptional<zod0.ZodString>;
34
35
  }, better_auth0.$strip>;
35
36
  metadata: {
36
37
  readonly scope: "server";
package/dist/index.mjs CHANGED
@@ -6,9 +6,18 @@ import * as z from "zod";
6
6
  //#region src/routes.ts
7
7
  const expoAuthorizationProxy = createAuthEndpoint("/expo-authorization-proxy", {
8
8
  method: "GET",
9
- query: z.object({ authorizationURL: z.string() }),
9
+ query: z.object({
10
+ authorizationURL: z.string(),
11
+ oauthState: z.string().optional()
12
+ }),
10
13
  metadata: HIDE_METADATA
11
14
  }, async (ctx) => {
15
+ const { oauthState } = ctx.query;
16
+ if (oauthState) {
17
+ const oauthStateCookie = ctx.context.createAuthCookie("oauth_state", { maxAge: 600 * 1e3 });
18
+ ctx.setCookie(oauthStateCookie.name, oauthState, oauthStateCookie.attributes);
19
+ return ctx.redirect(ctx.query.authorizationURL);
20
+ }
12
21
  const { authorizationURL } = ctx.query;
13
22
  const state = new URL(authorizationURL).searchParams.get("state");
14
23
  if (!state) throw new APIError("BAD_REQUEST", { message: "Unexpected error" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/expo",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "type": "module",
5
5
  "description": "Better Auth integration for Expo and React Native applications.",
6
6
  "main": "dist/index.mjs",
@@ -61,16 +61,16 @@
61
61
  "expo-web-browser": "~14.2.0",
62
62
  "react-native": "~0.80.2",
63
63
  "tsdown": "^0.17.2",
64
- "@better-auth/core": "1.4.12",
65
- "better-auth": "1.4.12"
64
+ "@better-auth/core": "1.4.13",
65
+ "better-auth": "1.4.13"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "expo-constants": ">=17.0.0",
69
69
  "expo-linking": ">=7.0.0",
70
70
  "expo-network": "^8.0.7",
71
71
  "expo-web-browser": ">=14.0.0",
72
- "@better-auth/core": "1.4.12",
73
- "better-auth": "1.4.12"
72
+ "better-auth": "1.4.13",
73
+ "@better-auth/core": "1.4.13"
74
74
  },
75
75
  "peerDependenciesMeta": {
76
76
  "expo-constants": {