-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(chat-otp): added db fallback for chat otp #2582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryReplaces unreliable in-memory OTP storage with database-backed fallback using the existing Key changes:
Benefits:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant API as OTP Route
participant Storage as getStorageMethod()
participant Redis
participant DB as Database (verification)
participant Email as Email Service
Note over Client,Email: POST - Request OTP
Client->>API: POST /api/chat/[identifier]/otp<br/>{email}
API->>DB: Query chat by identifier
DB-->>API: Return chat config
API->>API: Validate email against allowedEmails
API->>API: Generate 6-digit OTP
API->>Storage: Check storage method
alt Redis Storage
Storage-->>API: "redis"
API->>Redis: SET otp:email:chatId (EX 900)
Redis-->>API: OK
else Database Storage
Storage-->>API: "database"
API->>DB: BEGIN TRANSACTION
API->>DB: DELETE verification WHERE identifier=chat-otp:chatId:email
API->>DB: INSERT verification (id, identifier, value, expiresAt)
API->>DB: COMMIT TRANSACTION
DB-->>API: Success
end
API->>Email: Send OTP email
Email-->>API: Success
API-->>Client: 200 {message: "Verification code sent"}
Note over Client,Email: PUT - Verify OTP
Client->>API: PUT /api/chat/[identifier]/otp<br/>{email, otp}
API->>DB: Query chat by identifier
DB-->>API: Return chat config
API->>Storage: Check storage method
alt Redis Storage
Storage-->>API: "redis"
API->>Redis: GET otp:email:chatId
Redis-->>API: stored OTP
else Database Storage
Storage-->>API: "database"
API->>DB: SELECT * FROM verification<br/>WHERE identifier=chat-otp:chatId:email<br/>AND expiresAt > now
DB-->>API: Return OTP record
end
API->>API: Compare stored OTP with provided OTP
alt OTP Valid
API->>Storage: Check storage method
alt Redis Storage
API->>Redis: DEL otp:email:chatId
else Database Storage
API->>DB: DELETE verification WHERE identifier
end
API->>API: Set auth cookie
API-->>Client: 200 {authenticated: true}
else OTP Invalid
API-->>Client: 400 {error: "Invalid verification code"}
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
Summary
Type of Change
Testing
Tested manually
Checklist