[GH-ISSUE #6368] Expo Android App: Google Sign-In Fails on Second Attempt #19128

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

Originally created by @growupanand on GitHub (Nov 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6368

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • login with google sign in on android emulator
  • it will redirect to google sign page, and comeback to app with sign success
  • now sign out
  • then login again with google, you will see it will not redirect to browser window for google sign in page

Current vs. Expected behavior

Current
In the expo terminal i am getting below error:

 ERROR  OAuth login error: [Error: The WebBrowser's auth session is in an invalid state with a redirect handler set when it should not be] 

Expected

It should redirect to browser windows for google sign page

What version of Better Auth are you using?

1.4.3

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:06 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T6000",
    "release": "24.6.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "32.00 GB",
    "freeMemory": "3.46 GB"
  },
  "node": {
    "version": "v22.21.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.4"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Client, Package

Auth config (if applicable)


Additional context

I am using expo@~54.0.23.

I think the issue is that expo-web-browser maintains state between OAuth sessions. When the first OAuth session completes, the redirect handler isn't properly cleaned up, causing the second attempt to fail.

Originally created by @growupanand on GitHub (Nov 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6368 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce - login with google sign in on android emulator - it will redirect to google sign page, and comeback to app with sign success - now sign out - then login again with google, you will see it will not redirect to browser window for google sign in page ### Current vs. Expected behavior **Current** In the expo terminal i am getting below error: ``` ERROR OAuth login error: [Error: The WebBrowser's auth session is in an invalid state with a redirect handler set when it should not be] ``` **Expected** It should redirect to browser windows for google sign page ### What version of Better Auth are you using? 1.4.3 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:06 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T6000", "release": "24.6.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "32.00 GB", "freeMemory": "3.46 GB" }, "node": { "version": "v22.21.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.4" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client, Package ### Auth config (if applicable) ```typescript ``` ### Additional context I am using expo@~54.0.23. I think the issue is that expo-web-browser maintains state between OAuth sessions. When the first OAuth session completes, the redirect handler isn't properly cleaned up, causing the second attempt to fail.
GiteaMirror added the lockedbug labels 2026-04-15 17:55:24 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 28, 2025):

It appears that the error is coming from expo-web-browser holding on to a previous redirect handler during subsequent OAuth sessions. One troubleshooting step is to ensure that after signing out you are properly dismissing any active auth session—using expo-web-browser’s dismissAuthSession or clearing its cached state—so that a fresh redirect handler is established on the next sign-in attempt [3]. Could you try explicitly resetting the OAuth session between sign-ins and let me know if that resolves the issue? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3587846166 --> @better-auth-agent[bot] commented on GitHub (Nov 28, 2025): It appears that the error is coming from expo-web-browser holding on to a previous redirect handler during subsequent OAuth sessions. One troubleshooting step is to ensure that after signing out you are properly dismissing any active auth session—using expo-web-browser’s dismissAuthSession or clearing its cached state—so that a fresh redirect handler is established on the next sign-in attempt [[3]](https://github.com/better-auth/better-auth/issues/5072). Could you try explicitly resetting the OAuth session between sign-ins and let me know if that resolves the issue? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@pinkycollie commented on GitHub (Nov 28, 2025):

swift

<!-- gh-comment-id:3588282408 --> @pinkycollie commented on GitHub (Nov 28, 2025): swift
Author
Owner

@growupanand commented on GitHub (Nov 28, 2025):

This bug is in the Android app only, I found an temprory fix by manually redirecting to auth page. Below is the code:

const socialLoginResult = await expoAuthClient.signIn.social({
                provider: "google",
                callbackURL,
                // We will manually handle the browser redirect flow on Android
                disableRedirect: true,
            });

            const authUrl = socialLoginResult?.data?.url;

            if (!authUrl) {
                throw new Error("No auth URL returned from social sign-in");
            }

            const proxyURL = `${expoAuthClient.baseURL}/api/auth/expo-authorization-proxy?authorizationURL=${encodeURIComponent(authUrl)}`;
            const result = await Browser.openAuthSessionAsync(
                proxyURL,
                callbackURL,
            );
<!-- gh-comment-id:3588424121 --> @growupanand commented on GitHub (Nov 28, 2025): This bug is in the **Android app only**, I found an **temprory fix** by manually redirecting to auth page. Below is the code: ``` const socialLoginResult = await expoAuthClient.signIn.social({ provider: "google", callbackURL, // We will manually handle the browser redirect flow on Android disableRedirect: true, }); const authUrl = socialLoginResult?.data?.url; if (!authUrl) { throw new Error("No auth URL returned from social sign-in"); } const proxyURL = `${expoAuthClient.baseURL}/api/auth/expo-authorization-proxy?authorizationURL=${encodeURIComponent(authUrl)}`; const result = await Browser.openAuthSessionAsync( proxyURL, callbackURL, ); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19128