Skip to content

fix(auth): forget email-link reauthentication when it is cancelled or no user is signed in - #1431

Merged
demolaf merged 3 commits into
mainfrom
fix/stale-email-link-reauth
Nov 18, 2026
Merged

demolaf merged 3 commits into
mainfrom
fix/stale-email-link-reauth

Conversation

@demolaf

@demolaf demolaf commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Clears stored email-link reauthentication state when it is abandoned, so later sign-in links are handled as sign-in again. Stacked on #1430.

Changes

  • Cancelling or closing EmailLinkReauthView forgets the stored reauth email and flag, including when the close lands while the email is still sending. Before, the email-link screen skipped sign-in links and handleSignInLink(url:) routed them to reauthentication.
  • Swiping the email-link reauth sheet away now cancels the coordinator, so the caller waiting on reauthentication is not left hanging. A request made while the sheet closes is left alone.
  • Reauth state left with no signed-in (non-anonymous) user is ignored, not cleared, and the link is treated as sign-in. The check reads auth.currentUser, which is set before currentUser after a cold launch.
  • Integration tests cover cancelling and a sign-in link opened with leftover reauth state.

Preview

Recorded on an erased simulator in the e2e example app (--test-view-enabled), which signs out through Auth on relaunch, so the session ends without signOut(). Delete Account was patched locally to require a recent login, since the Auth emulator never does. Steps: sign in with an email link, Delete Account, cancel reauthentication, relaunch, then open a sign-in link for another user.

Before (#1430, 518defa19e)

Expected: when a user wants to sign in with an email link after a cancelled reauthentication, opening the link should sign them in.

pr1431-before.mp4

After (#1431, 98cc6ed8e0)

pr1431-after.mp4

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces state cleanup for email-link reauthentication when the process is cancelled, dismissed, or when there is no longer a signed-in user. It adds cancellation handlers in AuthService and the corresponding SwiftUI views, along with integration tests to verify the new behavior. The feedback suggests renaming the helper method hasPendingEmailLinkReauth() to checkAndCleanPendingEmailLinkReauth() (and updating its callsites) to better reflect its side-effects, adhering to the Command-Query Separation principle and Swift API Design Guidelines.

@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch from dd53050 to c9bbb50 Compare November 9, 2026 15:49
@demolaf
demolaf added this pull request to stack #1433 November 9, 2026 15:50
@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch 2 times, most recently from d9d1cd9 to 98cc6ed Compare November 10, 2026 15:56
@demolaf
demolaf marked this pull request as ready for review November 10, 2026 15:56
@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch from 98cc6ed to cf2a54d Compare November 13, 2026 12:22
@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch from cf2a54d to c28f09d Compare November 13, 2026 14:14
@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch 5 times, most recently from 8ff1816 to 96cf8cd Compare November 17, 2026 09:40

@russellwheatley russellwheatley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README line added in #1430 is out of date with this change: "AuthPickerView also completes it when the link opens the app after the sheet closed, for example after a cold launch." Closing the sheet (Cancel or swipe) now forgets the reauth state, so a link opened afterwards takes the sign-in path, and presentEmailLinkScreen bails because the user is signed in. The only case left is the app being killed with the sheet still up, since onDisappear never runs then. Could you reword it in this PR to just cover that? Something like "...when the app was closed while the sheet was showing and the link reopens it."

Base automatically changed from fix/email-link-reauth-cold-launch to main November 17, 2026 15:22
… no user is signed in

Cancelling or dismissing EmailLinkReauthView left the stored reauthentication state set, so later sign-in links were skipped by the email-link screen and routed to reauthentication. Clear that state when the view closes, cancel the coordinator when the sheet is swiped away, and drop leftover state when no user is signed in.
Forget the reauthentication a send stores after the view has closed, only cancel the coordinator on swipe-dismiss when no new request has started, and ignore leftover reauthentication without a signed-in user instead of clearing it, so a user that can't be read yet doesn't lose a pending one.
@demolaf
demolaf force-pushed the fix/stale-email-link-reauth branch from 96cf8cd to b36041a Compare November 17, 2026 15:22
@demolaf

demolaf commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

@russellwheatley Reworded in c5f57f6 to cover only the app being closed while the reauth sheet is showing. The retry sentence still holds, since nothing resumes the original action after a relaunch.

@demolaf
demolaf merged commit 152d0fc into main Nov 18, 2026
21 checks passed
@demolaf
demolaf deleted the fix/stale-email-link-reauth branch November 18, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants