Implement OTP-based mobile authentication with HttpOnly JWT cookies#10
Open
Aguthcoder wants to merge 1 commit intocodex/add-events-system-and-payment-featuresfrom
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
localStorageauth.Description
OtpCodeEntity(otp_codes) withotp_hash,expires_at,consumed_at,attempts, andcreated_atto store only hashed OTPs.POST /api/auth/request-otp,POST /api/auth/verify-otp, andPOST /api/auth/logout, with request/verify DTOs (RequestOtpDto,VerifyOtpDto) validatingfa-IRmobile and 6-digit OTP.AuthServicelogic to normalize Iranian mobile numbers, throttle requests (60s), generate 6-digit OTPs, HMAC-SHA256 hash OTPs withOTP_SECRET, enforce expiry (2 minutes) and attempt limits (max 5), auto-createUserEntitybymobile_number, and issue JWTaccessToken/refreshToken.accessToken(path/, TTL 15m) andrefreshToken(path/api/auth, TTL 30d), and updated JWT guard to readaccessTokenfrom cookies instead ofAuthorizationheader.UserEntityto add nullablemobileNumberand preserved existing fields; registeredOtpCodeEntityinAuthModule; added documentationbackend/docs/otp-auth-mvp.mdwith schema, API examples, Next.js middleware sample, and frontend usage (with Persian UX notes).Testing
cd backend && npm run build, but the build failed in this environment because thenestbinary was not available.npm install/npm ci) but could not produce a working build in this restricted environment, so unit/e2e tests were not executed.Codex Task