fix(auth): allow phone-first users to attach and verify email (#38482) #2156
+53
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses supabase/supabase#38482
.
When a user signs up with a phone number and later tries to add & verify an email with:
await supabase.auth.signInWithOtp({
email: "[email protected]",
options: { shouldCreateUser: false }
})
the API currently returns:
signup is not enabled for otp
because the request is mistakenly routed through the OTP signup flow instead of the email change/verification flow.
✅ Changes
Updated internal/api/otp.go (Otp handler) to detect when:
a user is already authenticated, and
shouldCreateUser == false with an email provided
→ Route to email verification / change flow instead of OTP signup.
Added startEmailChangeVerification helper to reuse existing email-change logic.
Added regression test in internal/api/otp_test.go:
TestAttachEmailToPhoneUser ensures attaching an email to a phone-first account now works correctly.
🧪 Test Plan
Run go test ./internal/api -run TestAttachEmailToPhoneUser.
Verified:
Normal OTP email/phone signups still pass.
Email-first users can still add phone.
Phone-first users can now add email without hitting "signup is not enabled for otp".
🔗 Related Issue
Closes supabase/supabase#38482
📚 Notes for Maintainers
No impact on fresh signups.
Only affects the signInWithOtp case when shouldCreateUser=false and a user session already exists.
Restores symmetry between email-first → add phone and phone-first → add email onboarding flows.
📸 Screenshots / Demo
N/A — server-side change. Confirmed via tests.
What kind of change does this PR introduce?
Bug fix, feature, docs update, ...
What is the current behavior?
Please link any relevant issues here.
What is the new behavior?
Feel free to include screenshots if it includes visual changes.
Additional context
Add any other context or screenshots.