Skip to content

Spec Doc for Email OTP Verification#226

Open
zandre-eng wants to merge 2 commits intomainfrom
ze/email-otp-verification-doc
Open

Spec Doc for Email OTP Verification#226
zandre-eng wants to merge 2 commits intomainfrom
ze/email-otp-verification-doc

Conversation

@zandre-eng
Copy link
Copy Markdown
Contributor

Technical Summary

Link to ticket here.
This is a release path 3 feature.

This PR contains a spec doc for implementing email OTP verification in PersonalID. Specifically, it will allow users to add an email address to their account which can be used in the future for verification purposes via email.

Please note, this PR will not be merged and exists solely for review purposes.

Logging and monitoring

N/A

Safety Assurance

Safety story

Just a spec document, this is not planned to be merged.

  • I am confident that this change will not break current and/or previous versions of CommCare apps

Automated test coverage

N/A

QA Plan

N/A

Labels & Review

  • The set of people pinged as reviewers is appropriate for the level of risk of the change

1. **Email uniqueness:** Should a verified email address be unique across active users (i.e. prevent two users from verifying the same address)? A unique constraint would add integrity but could cause friction if a user re-registers with the same email. **Recommendation:** leave uncontrained at MVP, revisit if abuse is observed.
2. **Email re-verification:** Can a user verify a different email address and overwrite their existing verified email?
3. **Test email bypass:** The design skips email delivery for users whose phone starts with `TEST_NUMBER_PREFIX`. Should a hardcoded test OTP (e.g. `"123456"`) be returned for test users, similar to any existing test-number shortcuts?
4. **Rate limit response code:** Should `send_email_otp` return `HTTP 429 Too Many Requests` with a `Retry-After` header when backoff is active, or a `400` with an error code? `429` is more semantically correct and aligns with RFC 6585.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shubham1g5 I'd like to get mobile's thoughts here on what you'd prefer as a response code?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

429 would be best for any rate limiting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@zandre-eng has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 13 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f57b3fc6-9519-4f7d-a81e-fee70df26959

📥 Commits

Reviewing files that changed from the base of the PR and between 33c49de and c8347f3.

📒 Files selected for processing (1)
  • docs/plans/2026-05-06-email-otp-verification-spec.md

Walkthrough

This PR introduces a comprehensive technical specification document for Email OTP verification. The spec outlines two new API endpoints (send_email_otp and verify_email_otp), model additions (email_verified field on ConnectUser, verified_email on ConfigurationSession, and a new EmailOTPDevice model), authentication flows for sign-up and post-registration contexts, feature-flag gating, SES-backed email delivery via AnyMail, Celery-driven async email sending with exponential backoff, monitoring and alerting strategy, deployment requirements, QA test workflows, and detailed API definitions and implementation tickets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Spec Doc for Email OTP Verification' directly and clearly describes the main change—a specification document for implementing email OTP verification.
Description check ✅ Passed The PR description is directly related to the changeset, providing technical context about the email OTP verification spec and reference to the associated ticket CCCT-2371.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ze/email-otp-verification-doc

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/plans/2026-05-06-email-otp-verification-spec.md`:
- Line 211: API auth entries for the endpoints incorrectly list only OAuth2;
update the two endpoint auth blocks (the ones showing "Authorization: Bearer
<personal_id_token>") to enumerate both SessionTokenAuthentication (used in the
sign-up/verification flow) and OAuth2Authentication (used post-registration) so
clients know to accept either method; specifically replace the single OAuth2
auth declaration with a dual-auth declaration referencing
SessionTokenAuthentication and OAuth2Authentication in those endpoint
definitions.
- Line 98: The spec uses an inconsistent endpoint name: change the modified view
heading and any occurrences of start_device_configuration to the canonical
endpoint name start_configuration to match the rest of the document; update the
header "**Modified view — `start_device_configuration`**" and any references
within the `start_configuration` section so implementation and QA use the same
endpoint name.
- Around line 112-116: The fenced code block containing the email template
starting with "Subject: Your CommCare Connect verification code" should include
a language tag to satisfy MD040; change the opening fence from ``` to ```text so
the block becomes ```text ... ``` and preserves the template (including the
"{token}" placeholder) while passing the markdown lint check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 630bbc75-429f-4b6a-b781-e264d5cb0a4e

📥 Commits

Reviewing files that changed from the base of the PR and between 1d4f968 and 33c49de.

📒 Files selected for processing (1)
  • docs/plans/2026-05-06-email-otp-verification-spec.md

Comment thread docs/plans/2026-05-06-email-otp-verification-spec.md Outdated
Comment thread docs/plans/2026-05-06-email-otp-verification-spec.md Outdated
Comment thread docs/plans/2026-05-06-email-otp-verification-spec.md Outdated
- **Sign-up flow** — the user optionally verifies an email during onboarding, before a `ConnectUser` account exists. Authentication uses a `ConfigurationSession` Bearer token (the same token returned by `start_configuration` and used by `complete_profile`), via `SessionTokenAuthentication`.
- **Post-registration flow** — an already-registered user verifies or updates their email. Authentication uses an OAuth2 Bearer token, via `OAuth2Authentication` (already the default in `REST_FRAMEWORK` settings).

Both flows use identical request/response payloads. The feature is gated behind a django-waffle flag (`email_otp_verification`) to allow a phased rollout.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clarifying that this is same as toggles that are sent in response for /start_configuration ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is correct. This will be a global switch for PersonalID that we can use to enable/disable this feature entirely on the platform.

| 200 | `{}` | OTP email sent (or queued if test user) |
| 400 | `{"error_code": "MISSING_DATA"}` | Missing or invalid email |
| 404 | — | Feature flag disabled |
| 429 | `{"error_code": "RATE_LIMITED", "retry_after_seconds": N}` | Backoff window not elapsed |
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If possible, can we name it EMAIL_RATE_LIMITED so that mobile code has more readability while handling it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That should be fine to do. @Jignesh-dimagi Would mobile also want MISSING_DATA to be EMAIL_MISSING_DATA for consistency?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Jignesh-dimagi I would vote for keeping them generic instead, if we are making a request to email API think it's quite obvious that the rate limiting error is around email and we should not need to append EMAIL_ to all these error codes.

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.

3 participants