[PR #5836] [MERGED] fix(expo): account linking flow on mobile #6263

Closed
opened 2026-03-13 12:52:47 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5836
Author: @almadoro
Created: 11/7/2025
Status: Merged
Merged: 11/7/2025
Merged by: @himself65

Base: canaryHead: canary


📝 Commits (2)

  • dfaf5ed fix(expo): preserve existing cookies on link-social flow
  • 9e78ef2 test(expo): evaluating new returned cookie is being set

📊 Changes

2 files changed (+36 additions, -1 deletions)

View changed files

📝 packages/expo/src/client.ts (+3 -1)
📝 packages/expo/test/expo.test.ts (+33 -0)

📄 Description

Fixes account linking flow on mobile (avoid overriding all cookies after a link-social call)

Currently, after linking a social account, the flow completes successfully, and everything looks good on the backend. However, in the app, the session is lost, causing it to enter an "unauthenticated" state.

I found that this occurs because the redirection URL after the social account linking flow looks something like this:

my-app:///a-path?cookie=better-auth.state%3D%3B+Max-Age%3D0%3B+Secure

This URL attempts to reset the state cookie but ends up wiping out all cookies instead.

This PR avoids that by using the following pattern already present in the same function:

const prevCookie = await storage.getItem(cookieName);
const toSetCookie = getSetCookie(cookie, prevCookie ?? undefined);
storage.setItem(cookieName, toSetCookie);

Context

  • Expo
  • Hono backend
  • Generic OAuth provider

Summary by cubic

Preserves existing cookies during the mobile link-social redirect so the session stays authenticated after account linking. Merges the new cookie with stored cookies instead of overwriting them.

  • Bug Fixes
    • Read the previous cookie and call getSetCookie(cookie, prevCookie) before storage.setItem.
    • Added a test to confirm new cookies are added and existing cookies remain unchanged.

Written for commit 9e78ef27d5. 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/5836 **Author:** [@almadoro](https://github.com/almadoro) **Created:** 11/7/2025 **Status:** ✅ Merged **Merged:** 11/7/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (2) - [`dfaf5ed`](https://github.com/better-auth/better-auth/commit/dfaf5ed888c0b02e1433a7efa195e1d1caa28725) fix(expo): preserve existing cookies on link-social flow - [`9e78ef2`](https://github.com/better-auth/better-auth/commit/9e78ef27d5781d90756dcdf887d4399a7708d864) test(expo): evaluating new returned cookie is being set ### 📊 Changes **2 files changed** (+36 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/expo/src/client.ts` (+3 -1) 📝 `packages/expo/test/expo.test.ts` (+33 -0) </details> ### 📄 Description # Fixes account linking flow on mobile (avoid overriding all cookies after a link-social call) Currently, after linking a social account, the flow completes successfully, and everything looks good on the backend. However, in the app, the session is lost, causing it to enter an "unauthenticated" state. I found that this occurs because the redirection URL after the social account linking flow looks something like this: `my-app:///a-path?cookie=better-auth.state%3D%3B+Max-Age%3D0%3B+Secure` This URL attempts to reset the state cookie but ends up wiping out all cookies instead. This PR avoids that by using the following pattern already present in the same function: ```ts const prevCookie = await storage.getItem(cookieName); const toSetCookie = getSetCookie(cookie, prevCookie ?? undefined); storage.setItem(cookieName, toSetCookie); ``` ## Context - Expo - Hono backend - Generic OAuth provider <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Preserves existing cookies during the mobile link-social redirect so the session stays authenticated after account linking. Merges the new cookie with stored cookies instead of overwriting them. - **Bug Fixes** - Read the previous cookie and call getSetCookie(cookie, prevCookie) before storage.setItem. - Added a test to confirm new cookies are added and existing cookies remain unchanged. <sup>Written for commit 9e78ef27d5781d90756dcdf887d4399a7708d864. 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 12:52:47 -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#6263