[GH-ISSUE #2116] Anonymous authentication fails with no error in Expo #26381

Closed
opened 2026-04-17 16:54:24 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @thecoorum on GitHub (Apr 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2116

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a bare Expo application
  2. Install better-auth and @better-auth/expo
  3. Configure server and client auth clients
    auth/server
import { betterAuth } from "better-auth";

import { anonymous } from "better-auth/plugins";
import { expo } from "@better-auth/expo";

import { drizzleAdapter } from "better-auth/adapters/drizzle";

import { db } from "@/database";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  emailAndPassword: {
    enabled: true,
  },
  trustedOrigins: ["wshz://"],
  plugins: [
    anonymous(),
    expo(),
  ],
});

auth/client

import { createAuthClient } from "better-auth/react";

import { anonymousClient } from "better-auth/client/plugins";
import { expoClient } from "@better-auth/expo/client";

import * as SecureStore from "expo-secure-store";

import type { BetterAuthClientPlugin } from "better-auth/types";

export const { signIn, signOut, signUp, useSession } = createAuthClient({
  baseURL: "http://localhost:8081",
  plugins: [
    anonymousClient(),
    expoClient({
      scheme: "wshz",
      storagePrefix: "wshz",
      storage: SecureStore,
    }) as BetterAuthClientPlugin,
  ],
});
  1. Try to authenticate anonymously

Current vs. Expected behavior

Expected: User is authenticated as anonymous user and data is successfully updated in useSession

Current: Authenticating anonymously fails with

try {
  const user = await signIn.anonymous()

  console.log(user) // {"data": null, "error": {"status": 0, "statusText": ""}}
} catch (error) {
  // No error caught here
  console.log(error)
}

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS: MacOS

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";

import { anonymous } from "better-auth/plugins";
import { expo } from "@better-auth/expo";

import { drizzleAdapter } from "better-auth/adapters/drizzle";

import { db } from "@/database";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  emailAndPassword: {
    enabled: true,
  },
  trustedOrigins: ["wshz://"],
  plugins: [
    anonymous(),
    expo(),
  ],
});

Additional context

No response

Originally created by @thecoorum on GitHub (Apr 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2116 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a bare Expo application 2. Install `better-auth` and `@better-auth/expo` 3. Configure server and client auth clients `auth/server` ```ts import { betterAuth } from "better-auth"; import { anonymous } from "better-auth/plugins"; import { expo } from "@better-auth/expo"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/database"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, }, trustedOrigins: ["wshz://"], plugins: [ anonymous(), expo(), ], }); ``` `auth/client` ```ts import { createAuthClient } from "better-auth/react"; import { anonymousClient } from "better-auth/client/plugins"; import { expoClient } from "@better-auth/expo/client"; import * as SecureStore from "expo-secure-store"; import type { BetterAuthClientPlugin } from "better-auth/types"; export const { signIn, signOut, signUp, useSession } = createAuthClient({ baseURL: "http://localhost:8081", plugins: [ anonymousClient(), expoClient({ scheme: "wshz", storagePrefix: "wshz", storage: SecureStore, }) as BetterAuthClientPlugin, ], }); ``` 4. Try to authenticate anonymously ### Current vs. Expected behavior Expected: User is authenticated as anonymous user and data is successfully updated in `useSession` Current: Authenticating anonymously fails with ```ts try { const user = await signIn.anonymous() console.log(user) // {"data": null, "error": {"status": 0, "statusText": ""}} } catch (error) { // No error caught here console.log(error) } ``` ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS: MacOS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { anonymous } from "better-auth/plugins"; import { expo } from "@better-auth/expo"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/database"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, }, trustedOrigins: ["wshz://"], plugins: [ anonymous(), expo(), ], }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 16:54:24 -05:00
Author
Owner

@Bekacru commented on GitHub (Apr 4, 2025):

Make sure the server is being reached by the client. The above error is returned when the client didn't receive any response.

<!-- gh-comment-id:2779066167 --> @Bekacru commented on GitHub (Apr 4, 2025): Make sure the server is being reached by the client. The above error is returned when the client didn't receive any response.
Author
Owner

@kabukki commented on GitHub (Apr 4, 2025):

I had the same error and it came from a scheme mismatch in my app.json

<!-- gh-comment-id:2779486633 --> @kabukki commented on GitHub (Apr 4, 2025): I had the same error and it came from a scheme mismatch in my `app.json`
Author
Owner

@thecoorum commented on GitHub (Apr 4, 2025):

Yes, it was the server not reached error. Probably, it was happening while using Radon IDE for React Native and localhost for separate server, but using ngrok resolved the issue

<!-- gh-comment-id:2779590760 --> @thecoorum commented on GitHub (Apr 4, 2025): Yes, it was the server not reached error. Probably, it was happening while using Radon IDE for React Native and localhost for separate server, but using ngrok resolved the issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26381