Source of Truth
Current Codebase Snapshot
src/routes/v1/auth.route.ts currently exposes register, login, refresh, and me.
prisma/schema.prisma already stores email_verified and phone_verified on User.
- The backend does not yet implement email verification, phone OTP verification, forgot-password, optional 2FA, step-up auth, or reCAPTCHA validation.
Goal
Upgrade auth from a basic login/register layer into the canonical trust boundary for the product. After this task, every other domain should be able to trust auth for identity, verified-contact status, and high-risk re-authentication.
In Scope
- Email verification using single-use magic links with expiry and resend support.
- Phone verification using OTP with resend, TTL, and rate limiting.
- Forgot-password and reset-password using a single-use reset token with 1-hour TTL.
- Optional 2FA enrollment and login challenge flow.
- reCAPTCHA validation on register and login.
- Machine-readable restriction state for
logged in but not fully verified users.
- Step-up auth for
delete account, email change, phone change, and delete brand.
- Swagger/OpenAPI updates and automated tests.
Suggested Implementation Order
- Extend Prisma with verification tokens, OTP challenges, password reset tokens, and 2FA enrollment/challenge tables.
- Add services for token generation, hashing, expiry validation, single-use consumption, and rate limiting.
- Add endpoints for verify/resend/reset/2FA setup and challenge flows.
- Add middleware/helpers so downstream domains can enforce
fully verified or step-up required consistently.
- Add reCAPTCHA verification behind a small adapter so it can be mocked in tests.
- Add integration tests for happy path, expiry, replay, rate limit, and invalid token cases.
Deliverables
- Prisma migration(s) and schema updates.
- New auth endpoints and service layer.
- Shared guard/helper for contact-verification and step-up requirements.
- Consistent error/response contract that frontend can consume without guessing.
- Test coverage for all security-sensitive flows.
Acceptance Criteria
- A newly registered user can verify email via magic link and phone via OTP.
- Non-verified users can authenticate but are blocked from non-User-domain actions via a consistent backend contract.
- Forgot-password works with single-use, expiring tokens.
- Optional 2FA can be enabled and challenged during login.
- High-risk actions require a recent step-up auth check.
- Register/login fail cleanly when reCAPTCHA verification fails.
- All tokens/challenges are single-use, expiring, and covered by tests.
Out of Scope
- Social login, passkeys, and full identity-provider integrations.
- Building an SMS/email provider from scratch beyond the adapter/hooks needed by this repo.
Source of Truth
Reziphay/nodejs-appnextjs-app#6and indirectly most protected-domain workCurrent Codebase Snapshot
src/routes/v1/auth.route.tscurrently exposesregister,login,refresh, andme.prisma/schema.prismaalready storesemail_verifiedandphone_verifiedonUser.Goal
Upgrade auth from a basic login/register layer into the canonical trust boundary for the product. After this task, every other domain should be able to trust auth for identity, verified-contact status, and high-risk re-authentication.
In Scope
logged in but not fully verifiedusers.delete account,email change,phone change, anddelete brand.Suggested Implementation Order
fully verifiedorstep-up requiredconsistently.Deliverables
Acceptance Criteria
Out of Scope