fix(authenticate): read otp attempt counter from json-decoded metadata - #1846
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe 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. ChangesOTP attempt metadata
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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. Comment |
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 anotpAttemptshelper that reads the attempt counter with a type switch overintandfloat64; count the current wrong code before the cap check, so the third wrong code destroys the flow.core/authenticate/service_test.go: add ajsonFlowRepositoryfake 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
go test -race -count 2 ./core/authenticate/passesgolangci-lint runreports 0 issues🤖 Generated with Claude Code