fix: distinguish first-time sign-up from returning login in OTP emails - #5
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR refactors the auth service to extract a reusable utility function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
188dc31 to
40f4772
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The sendVerificationOTP callback was using `type === 'sign-in'` to determine isNewUser, but all callers pass type='sign-in', so the welcome template was always used regardless of whether the user had an existing account. Now checks PDS account existence via /_internal/account-by-email before sending the OTP — new users (no PDS account yet) get the welcome email, returning users get the simpler sign-in code email. Fixes: atproto-n1n
Deduplicate the account-by-email fetch logic that was repeated in better-auth.ts, complete.ts, and account-settings.ts into a single lib/get-did-by-email.ts function. Add 11 tests covering all branches. Update better-auth-otp tests to use the real function instead of duplicating the isNewUser logic.
40f4772 to
c718f4e
Compare
Summary
sendVerificationOTPcallback usedtype === 'sign-in'to determineisNewUser, but all callers passtype: 'sign-in', so the welcome template was always used — even for returning users/_internal/account-by-emailbefore sending the OTP emailHow it works
In
better-auth.ts, thesendVerificationOTPcallback now calls the PDS internal API to check if an account exists for the email:isNewUser = false→ "Your sign-in code for ePDS"isNewUser = true→ "Welcome to ePDS"This matches the same pattern used in
complete.tsfor consent gating.Fixes: atproto-n1n
Depends on: #3 (merged)
Summary by CodeRabbit
New Features
Documentation
Refactor
Tests