Expo Client plugin causes crash importing expo-web-browser when using Expo for TV #1217

Closed
opened 2026-03-13 08:28:46 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jschoeny on GitHub (May 17, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Current vs. Expected behavior

Currently, the Better Auth Expo plugin does not distinguish as to whether the current platform is a TV or not. Because Expo for TV does not bundle the expo-web-browser package in the app, a crash occurs when Better Auth's expoClient plugin tries to import it.

Expected behavior would be to have the expoClient plugin not use the expo-web-browser package when the current platform is a TV. For reference, the following changes to packages/expo/src/client.ts allows the Expo TV app to run without crashing:

  import type { BetterAuthClientPlugin, Store } from "better-auth";
- import * as Browser from "expo-web-browser";
  import * as Linking from "expo-linking";
  import { Platform } from "react-native";
  import Constants from "expo-constants";
  import { BetterFetchOption } from "@better-fetch/fetch";
      fetchPlugins: [
        {
          id: "expo",
          name: "Expo",
          hooks: {
            async onSuccess(context) {
              if (isWeb) return;
              const setCookie = context.response.headers.get("set-cookie");
              if (setCookie) {
                const prevCookie = await storage.getItem(cookieName);
                const toSetCookie = getSetCookie(
                  setCookie || "",
                  prevCookie ?? undefined,
                );
                await storage.setItem(cookieName, toSetCookie);
                store?.notify("$sessionSignal");
              }

              if (
                context.request.url.toString().includes("/get-session") &&
                !opts?.disableCache
              ) {
                const data = context.data;
                storage.setItem(localCacheName, JSON.stringify(data));
              }

-             if (
-               context.data?.redirect &&
-               context.request.url.toString().includes("/sign-in") &&
-               !context.request?.body.includes("idToken") // id token is used for silent sign-in
-             ) {
-               const callbackURL = JSON.parse(context.request.body)?.callbackURL;
-               const to = callbackURL;
-               const signInURL = context.data?.url;
-               const result = await Browser.openAuthSessionAsync(signInURL, to);
-               if (result.type !== "success") return;
-               const url = new URL(result.url);
-               const cookie = String(url.searchParams.get("cookie"));
-               if (!cookie) return;
-               storage.setItem(cookieName, getSetCookie(cookie));
-               store?.notify("$sessionSignal");
-             }
            },
          },

### What version of Better Auth are you using?

1.2.8

### Provide environment information

```bash
- OS: macOS 14.6.1
- Platform: Expo / Apple TV

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { createAuthClient } from "better-auth"
import { expoClient } from "@better-auth/expo/client"
import * as SecureStore from "expo-secure-store"

export const authClient = createAuthClient({
  plugins: [
    expoTv({
      scheme: 'mytvapp',
      storagePrefix: 'mytvapp',
      storage: SecureStore,
    )},
  ],  
});

Additional context

Platform from react-native includes a isTV property to check whether the current platform is a TV.

Originally created by @jschoeny on GitHub (May 17, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - Follow the instructions to create a React Native TV app using Expo: https://docs.expo.dev/guides/building-for-tv/ - Follow the instructions to add Better Auth to the Expo app (client only): https://www.better-auth.com/docs/integrations/expo - Run the app - App will crash with the error `Cannot find native module 'ExpoWebBrowser'`, pointing back to `import { expoClient } from '@better-auth/expo/client'` ### Current vs. Expected behavior Currently, the Better Auth Expo plugin does not distinguish as to whether the current platform is a TV or not. Because Expo for TV does not bundle the `expo-web-browser` package in the app, a crash occurs when Better Auth's `expoClient` plugin tries to import it. Expected behavior would be to have the `expoClient` plugin not use the `expo-web-browser` package when the current platform is a TV. For reference, the following changes to [packages/expo/src/client.ts](https://github.com/better-auth/better-auth/blob/e7aec18d7d297da2d0c8e3b85c348a459b6d0ae0/packages/expo/src/client.ts#L173-L188) allows the Expo TV app to run without crashing: ```diff import type { BetterAuthClientPlugin, Store } from "better-auth"; - import * as Browser from "expo-web-browser"; import * as Linking from "expo-linking"; import { Platform } from "react-native"; import Constants from "expo-constants"; import { BetterFetchOption } from "@better-fetch/fetch"; ``` ```diff fetchPlugins: [ { id: "expo", name: "Expo", hooks: { async onSuccess(context) { if (isWeb) return; const setCookie = context.response.headers.get("set-cookie"); if (setCookie) { const prevCookie = await storage.getItem(cookieName); const toSetCookie = getSetCookie( setCookie || "", prevCookie ?? undefined, ); await storage.setItem(cookieName, toSetCookie); store?.notify("$sessionSignal"); } if ( context.request.url.toString().includes("/get-session") && !opts?.disableCache ) { const data = context.data; storage.setItem(localCacheName, JSON.stringify(data)); } - if ( - context.data?.redirect && - context.request.url.toString().includes("/sign-in") && - !context.request?.body.includes("idToken") // id token is used for silent sign-in - ) { - const callbackURL = JSON.parse(context.request.body)?.callbackURL; - const to = callbackURL; - const signInURL = context.data?.url; - const result = await Browser.openAuthSessionAsync(signInURL, to); - if (result.type !== "success") return; - const url = new URL(result.url); - const cookie = String(url.searchParams.get("cookie")); - if (!cookie) return; - storage.setItem(cookieName, getSetCookie(cookie)); - store?.notify("$sessionSignal"); - } }, }, ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: macOS 14.6.1 - Platform: Expo / Apple TV ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { createAuthClient } from "better-auth" import { expoClient } from "@better-auth/expo/client" import * as SecureStore from "expo-secure-store" export const authClient = createAuthClient({ plugins: [ expoTv({ scheme: 'mytvapp', storagePrefix: 'mytvapp', storage: SecureStore, )}, ], }); ``` ### Additional context `Platform` from `react-native` includes a `isTV` property to check whether the current platform is a TV.
Author
Owner

@dosubot[bot] commented on GitHub (Aug 16, 2025):

Hi, @jschoeny. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the Better Auth Expo client plugin crashes on Expo for TV due to the absence of the bundled expo-web-browser package.
  • You suggested updating the plugin to detect the TV platform and avoid importing expo-web-browser to prevent the crash.
  • You provided a code snippet demonstrating how to modify the plugin for compatibility with Expo TV.
  • There has been no further activity or comments on this issue since your initial report.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of the better-auth repository by commenting here.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 16, 2025): Hi, @jschoeny. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that the Better Auth Expo client plugin crashes on Expo for TV due to the absence of the bundled `expo-web-browser` package. - You suggested updating the plugin to detect the TV platform and avoid importing `expo-web-browser` to prevent the crash. - You provided a code snippet demonstrating how to modify the plugin for compatibility with Expo TV. - There has been no further activity or comments on this issue since your initial report. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of the better-auth repository by commenting here. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1217