Skip to content

feat(auth): confirm the email when a sign-in link opens on another device - #1429

Merged
demolaf merged 6 commits into
mainfrom
auth/email-link-same-device
Nov 16, 2026
Merged

demolaf merged 6 commits into
mainfrom
auth/email-link-same-device

Conversation

@demolaf

@demolaf demolaf commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Restores v15's cross-device email-link sign-in: a link opened on a device that didn't request it asks for the email address instead of failing. forceSameDevice keeps links on the requesting device. Builds on #1428.

Changes

  • Sign-in links carry ui_sid and ui_sd as in v15, and keep the app's own continue-URL parameters instead of replacing them.
  • EmailLinkContentState gains needsEmailConfirmation, confirmEmail and cancelConfirmation, with init defaults, and the stock screen shows a Confirm Email step. handleSignInLink(url:) still throws for such a link and also keeps it in pendingEmailLink; sign-out, closing the sheet or a used link clears it.
  • AuthPickerView opens the email-link screen when the app receives a link while that screen isn't showing, as after a cold launch or on another device. A call with a link already being handled waits for that attempt and gets its result, so apps' own onOpenURL handlers keep working.
  • Reads the continue URL before the link's second decode, which split off every continue-URL parameter after the first.

API Usage

authService.withEmailLinkSignIn(forceSameDevice: false)

EmailLinkScreen { state in
  if state.needsEmailConfirmation {
    Text("Enter the email this link was sent to")
  }
  TextField("Email", text: state.email)
  Button(state.needsEmailConfirmation ? "Confirm" : "Send link") {
    if state.needsEmailConfirmation {
      state.confirmEmail()
    } else {
      state.sendSignInLink()
    }
  }
  .disabled(!state.isValid || state.isLoading)
  if state.needsEmailConfirmation {
    Button("Send a new link", action: state.cancelConfirmation)
  }
}

Preview


Maintainer note: Fixes internal CPRN-640

@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 enhances the email link sign-in flow by adding support for cross-device sign-in, allowing users to confirm their email address when opening a link on a different device unless forceSameDevice is enabled. The changes include tracking pending links and session IDs in AuthService, updating the UI in EmailLinkScreen and DefaultEmailLinkContent to support the confirmation state, and adding comprehensive integration tests. The review feedback suggests several robust improvements: copying the shared ActionCodeSettings to prevent concurrent mutation issues, guarding against unrelated deep links early in handleSignInLink, and implementing a mechanism to clear the pending email link state when navigating away to prevent the UI from getting stuck in confirmation mode.

@demolaf
demolaf force-pushed the auth/email-link-same-device branch from 43994e1 to e74d5a5 Compare November 4, 2026 19:24
@demolaf
demolaf force-pushed the auth/email-link-same-device branch from e74d5a5 to 2fef1b8 Compare November 9, 2026 15:41
@demolaf
demolaf added this pull request to stack #1433 November 9, 2026 15:50
@demolaf
demolaf marked this pull request as ready for review November 10, 2026 14:25
@demolaf
demolaf force-pushed the auth/email-link-same-device branch from 0325fa6 to 3036794 Compare November 10, 2026 14:30
@demolaf
demolaf force-pushed the auth/email-link-same-device branch from 3036794 to 47eed83 Compare November 10, 2026 15:56
@demolaf
demolaf force-pushed the auth/email-link-same-device branch 2 times, most recently from 9170a9f to 2aae885 Compare November 13, 2026 16:14
Base automatically changed from auth/email-signup-options to main November 16, 2026 12:33
…links

The action-code builder replaced the continue URL's query items with ui_auid alone, dropping parameters the app put on it. Keep them and drop only the items the library writes, since the configured settings object is reused for every link.
…vice

Restores the FirebaseUI-iOS v15 cross-device email-link flow. Links carry ui_sid and ui_sd; a link opened without this device's session asks the user to confirm their email through EmailLinkContentState.needsEmailConfirmation and confirmEmail, or is rejected when withEmailLinkSignIn(forceSameDevice: true) is set. AuthPickerView now opens the email-link screen for a link received while that screen isn't showing, and the continue URL is read before the link's second decode, which dropped every continue-URL parameter after the first.
A link waiting for email confirmation stayed pending after sign-out, a closed sheet or a used link, so the email-link screen kept asking for an email and never offered to send a new link. Clear it in those cases and add cancelEmailLinkConfirmation with a cancelConfirmation action on EmailLinkContentState. Also leave opened links to an app's own email-link screen, and stop treating a link without ui_sid as this device's once a newer link was sent.
A link opened on another device threw before this change, and apps may rely on that, so keep throwing invalidEmailLink while also setting pendingEmailLink; the stock screen shows the confirm step instead of the error. Ignore a link that is already being handled or already signed in, so AuthPickerView and an app's own onOpenURL handler don't both use the same one-time link.
A second handleSignInLink call with a link already being handled returned at once, so an app's own onOpenURL could treat a failed sign-in as done. It now waits for the first attempt and gets its result. EmailLinkScreen hides the cross-device error only for the link that set pendingEmailLink, and signing out forgets the last used link so tapping it again reports that it expired.
EmailLinkScreen and EmailLinkReauthScreen handled every URL the app opened, so an unrelated deep link opened while either showed an error. They now handle only Firebase email sign-in links. Leaving EmailLinkScreen also drops a link waiting for email confirmation, so returning to it offers to send a new link.
@demolaf
demolaf force-pushed the auth/email-link-same-device branch from 2aae885 to 49ec541 Compare November 16, 2026 12:33
@demolaf
demolaf merged commit b7543a8 into main Nov 16, 2026
21 checks passed
@demolaf
demolaf deleted the auth/email-link-same-device branch November 16, 2026 13:08
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