[PR #6388] [MERGED] fix(expo): dismiss auth session on android to prevent invalid state error #6633

Closed
opened 2026-03-13 13:06:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6388
Author: @GautamBytes
Created: 11/28/2025
Status: Merged
Merged: 11/30/2025
Merged by: @Bekacru

Base: canaryHead: fix/expo-android-signin-state


📝 Commits (1)

  • 6716b87 fix(expo): dismiss auth session on android to prevent invalid state error

📊 Changes

1 file changed (+7 additions, -0 deletions)

View changed files

📝 packages/expo/src/client.ts (+7 -0)

📄 Description

Fixes #6368

The Issue

On Android, expo-web-browser maintains a stale redirect handler state if the previous OAuth session isn't explicitly dismissed. This causes subsequent sign-in attempts (after a sign-out) to fail with the error:
[Error: The WebBrowser's auth session is in an invalid state with a redirect handler set when it should not be]

The Fix

  • Added a Platform.OS === "android" check in the onSuccess hook.
  • Explicitly calls Browser.dismissAuthSession() before opening a new session to ensure the browser state is clean.

Summary by cubic

Dismiss the Android auth session before starting a new OAuth flow to prevent the “invalid state” error. This makes sign-in after sign-out work reliably on Android.

  • Bug Fixes
    • On Android, call Browser.dismissAuthSession() before opening a new auth session.
    • Wrap dismiss call in try/catch to ignore cases with no existing session.
    • No changes for iOS or web.

Written for commit 6716b87050. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6388 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 11/28/2025 **Status:** ✅ Merged **Merged:** 11/30/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/expo-android-signin-state` --- ### 📝 Commits (1) - [`6716b87`](https://github.com/better-auth/better-auth/commit/6716b870507136fbdcb8dce7882d8ee1cb3fce0a) fix(expo): dismiss auth session on android to prevent invalid state error ### 📊 Changes **1 file changed** (+7 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/expo/src/client.ts` (+7 -0) </details> ### 📄 Description Fixes #6368 ### The Issue On Android, `expo-web-browser` maintains a stale redirect handler state if the previous OAuth session isn't explicitly dismissed. This causes subsequent sign-in attempts (after a sign-out) to fail with the error: `[Error: The WebBrowser's auth session is in an invalid state with a redirect handler set when it should not be]` ### The Fix - Added a `Platform.OS === "android"` check in the `onSuccess` hook. - Explicitly calls `Browser.dismissAuthSession()` before opening a new session to ensure the browser state is clean. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Dismiss the Android auth session before starting a new OAuth flow to prevent the “invalid state” error. This makes sign-in after sign-out work reliably on Android. - **Bug Fixes** - On Android, call Browser.dismissAuthSession() before opening a new auth session. - Wrap dismiss call in try/catch to ignore cases with no existing session. - No changes for iOS or web. <sup>Written for commit 6716b870507136fbdcb8dce7882d8ee1cb3fce0a. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:06:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6633