auth icon indicating copy to clipboard operation
auth copied to clipboard

linkIdentity rejects phone-only users when an email-optional OIDC identity has no email

Open nml121 opened this issue 4 months ago • 3 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and existing issues.

Describe the bug

When linking an email-optional OIDC identity to an existing confirmed phone-only user, linkIdentityToUser creates the identity and calls UpdateUserEmailFromIdentities(). The resulting primary email is still empty, but because the provider claim has EmailVerified=false, the function enters the email-confirmation branch and calls sendConfirmation().

This makes a no-email identity depend on email delivery. On hosted Supabase the first surfaced error was over_email_send_rate_limit. In an isolated regression test against current master, the call returns 422:

Unverified email with custom:line. A confirmation email has been sent to your custom:line email

The identity-linked security notification is disabled and is not the failing branch.

To reproduce

  1. Create and persist a user with a confirmed phone, an empty email, and a phone identity.
  2. Call linkIdentityToUser for a unique custom OIDC provider subject with an empty email and EmailVerified=false.
  3. Expect linking to succeed and preserve the confirmed phone.
  4. Observe ErrorCodeEmailNotConfirmed instead.

The relevant path is currently:

internal/api/identity.go

targetUser.GetEmail() == "" -> UpdateUserEmailFromIdentities() -> !userData.Metadata.EmailVerified -> sendConfirmation()

Issue #634 added support for providers without email, but this linking path still assumes that an unverified email exists.

Expected behavior

When manual linking and email_optional are enabled, an authenticated confirmed phone-only user should be able to link an OIDC identity that has a stable provider subject and no email. No email confirmation should be attempted when the resulting primary email is empty.

A minimal fix is to run the existing email verification/confirmation block only when targetUser.GetEmail() != "". I added an isolated regression test and verified:

  • before the change: focused test fails with 422 EmailNotConfirmed
  • after the change: focused test passes
  • existing TestIdentity suite passes

The anonymous-user transition remains outside that conditional.

System information

  • Supabase Auth: current master source plus hosted Supabase observation
  • supabase-js: 2.108.2
  • Node.js: 24.13.1
  • OS: macOS

Additional context

This flow deliberately has no email: the canonical identity is a verified phone and the linked provider does not expose email. Creating a placeholder email or merging by provider metadata would weaken the identity model and should not be required for manual linking.

nml121 avatar Jul 23 '26 03:07 nml121

Opened a fix for this in a PR — linkIdentityToUser was treating “primary email is still empty” as “we just claimed an unverified email,” so phone-only users linking an email-optional OIDC identity with no email went through sendConfirmation and failed with 422 EmailNotConfirmed (or rate-limit noise on hosted).

The change mirrors the empty-email skip already used on signup: after UpdateUserEmailFromIdentities, confirmation / Confirm only runs when GetEmail() != "". The anonymous → non-anonymous transition is unchanged. Added TestLinkIdentityToUser_PhoneOnlyNoEmail to cover the regression.

Happy to adjust if anything looks off in review.

rohanpatel2002 avatar Jul 24 '26 15:07 rohanpatel2002

Confirmed this on current master. The primary email is still empty after UpdateUserEmailFromIdentities when the linked identity is email-optional, so the !EmailVerified branch calls sendConfirmation and returns email_not_confirmed for an address that doesn't exist.

Guarding the confirmation block on GetEmail() != "" (keeping the anonymous transition outside it) fixes it. I added a regression test plus a control case so the normal unverified-email path still asks for confirmation.

Happy to open a PR - let me know if you're already working on one.

hamodywe avatar Aug 14 '26 21:08 hamodywe

When will the new version be released?

guoqianghao9 avatar Sep 23 '26 02:09 guoqianghao9