🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(authenticate): read otp attempt counter from json-decoded metadata - #1846

Merged
AmanGIT07 merged 1 commit into
mainfrom
fix/otp-attempt-counter
Aug 4, 2026
Merged

fix(authenticate): read otp attempt counter from json-decoded metadata#1846
AmanGIT07 merged 1 commit into
mainfrom
fix/otp-attempt-counter

Conversation

@AmanGIT07

@AmanGIT07 AmanGIT07 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Flow metadata is stored as JSON, and JSON decoding returns numbers as float64. The mail OTP wrong-code attempt counter now handles both int and float64 when read from flow metadata, and the flow is destroyed when the counter reaches the attempt cap.

Changes

  • core/authenticate/service.go: add an otpAttempts helper that reads the attempt counter with a type switch over int and float64; count the current wrong code before the cap check, so the third wrong code destroys the flow.
  • core/authenticate/service_test.go: add a jsonFlowRepository fake that stores flow metadata as JSON bytes like the Postgres repository, plus a test walking the counter to the cap; seed the mock-based destroy case at the boundary.

Test Plan

  • Manual testing completed
  • Build and type checking passes
  • go test -race -count 2 ./core/authenticate/ passes
  • golangci-lint run reports 0 issues

🤖 Generated with Claude Code

Flow metadata is stored as JSON, and JSON decoding returns numbers as
float64. Read the wrong-code attempt counter with a type switch covering
int and float64, and destroy the flow when the counter reaches the
attempt cap. Add a test that round-trips flow metadata through JSON the
way the store layer does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview Aug 4, 2026 10:33am

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ac4fcd48-6edb-42a2-8a34-3e499a5670d2

📥 Commits

Reviewing files that changed from the base of the PR and between ad5e9a5 and b0280c2.

📒 Files selected for processing (2)
  • core/authenticate/service.go
  • core/authenticate/service_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved one-time passcode attempt tracking when authentication data is processed through database serialization.
    • Ensured invalid passcode attempts consistently enforce the maximum retry limit and remove the authentication flow when exceeded.

Walkthrough

The authentication service now handles OTP attempt metadata stored as integers or JSON-decoded floats. Tests add a JSON-backed repository fixture and verify attempt persistence and flow deletion when the invalid-code cap is reached.

Changes

OTP attempt metadata

Layer / File(s) Summary
Attempt counter handling
core/authenticate/service.go
The service normalizes OTP attempt metadata from int and float64 values. Mail OTP failure handling uses the normalized count before incrementing and persisting it.
JSON round-trip validation
core/authenticate/service_test.go
Tests add a JSON-backed repository fixture and verify that three invalid OTPs persist float64 attempts before deleting the flow at the cap.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: rohilsurana

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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.

@AmanGIT07
AmanGIT07 merged commit 6ccc7ba into main Aug 4, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the fix/otp-attempt-counter branch August 4, 2026 11:37
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.

2 participants