Repository navigation
feat: check-in feature integrates Turnstile security check - #2571
Conversation
WalkthroughThe changes introduce a Turnstile-based security verification layer for check-in functionality, adding middleware validation on the backend and a conditional modal-based security challenge flow on the frontend that triggers when check-in attempts fail. Changes
Sequence DiagramsequenceDiagram
participant UI as CheckinCalendar UI
participant API as Backend API
participant Turnstile as Turnstile Widget
participant Service as Verification Service
UI->>API: POST /api/user/checkin (without token)
API->>API: TurnstileCheck Middleware
API-->>UI: Error (requires Turnstile)
alt Turnstile Required
UI->>UI: Show Turnstile Modal
UI->>Turnstile: Initialize Widget
Turnstile-->>UI: Challenge Complete (token)
UI->>API: POST /api/user/checkin?turnstile=token
else User Cancels
UI->>UI: Close Modal & Reset Widget
end
API->>Service: Verify Token & Process Check-in
Service-->>API: Success/Failure
alt Success
API-->>UI: Check-in Confirmed
UI->>UI: Close Modal, Show Success
else Failure with Turnstile
API-->>UI: Refresh Required
UI->>UI: Reset Widget Key (Reinitialize)
else Other Error
API-->>UI: Error Message
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
web/src/services/secureVerification.js (1)
45-71: Inconsistent debug logging cleanup.Lines 45-50 comment out debug logs, but lines 59-71 still contain active
console.logstatements that expose calculation details (success status, enabled flags). Consider commenting out or removing these as well for consistency.🔎 Proposed fix
- console.log('has2FA calculation:', { - success: twoFAResponse.data?.success, - dataExists: !!twoFAResponse.data?.data, - enabled: twoFAResponse.data?.data?.enabled, - result: has2FA, - }); - - console.log('hasPasskey calculation:', { - success: passkeyResponse.data?.success, - dataExists: !!passkeyResponse.data?.data, - enabled: passkeyResponse.data?.data?.enabled, - result: hasPasskey, - }); + // console.log('has2FA calculation:', { + // success: twoFAResponse.data?.success, + // dataExists: !!twoFAResponse.data?.data, + // enabled: twoFAResponse.data?.data?.enabled, + // result: has2FA, + // }); + + // console.log('hasPasskey calculation:', { + // success: passkeyResponse.data?.success, + // dataExists: !!passkeyResponse.data?.data, + // enabled: passkeyResponse.data?.data?.enabled, + // result: hasPasskey, + // });web/src/components/settings/personal/cards/CheckinCalendar.jsx (2)
116-127: Consider refiningshouldTriggerTurnstilelogic.The current implementation returns
truefor any non-string message when Turnstile is enabled (line 125), which may incorrectly trigger the Turnstile modal for unrelated errors (e.g., network failures returningundefined). Consider being more explicit:🔎 Proposed fix
const shouldTriggerTurnstile = (message) => { if (!turnstileEnabled) return false; - if (typeof message !== 'string') return true; - return message.includes('Turnstile'); + if (typeof message !== 'string') return false; + return message.includes('Turnstile') || message.includes('turnstile'); };
217-226: Modal title should be internationalized.The modal title "Security Check" is hardcoded in English. Use the translation function for consistency with the rest of the component.
🔎 Proposed fix
<Modal - title='Security Check' + title={t('安全验证')} visible={turnstileModalVisible} footer={null} centered
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
router/api-router.goweb/src/components/settings/PersonalSetting.jsxweb/src/components/settings/personal/cards/CheckinCalendar.jsxweb/src/services/secureVerification.js
🧰 Additional context used
🧬 Code graph analysis (3)
router/api-router.go (2)
middleware/turnstile-check.go (1)
TurnstileCheck(17-81)controller/checkin.go (1)
DoCheckin(47-72)
web/src/components/settings/personal/cards/CheckinCalendar.jsx (1)
web/src/components/settings/PersonalSetting.jsx (2)
turnstileEnabled(67-67)turnstileSiteKey(68-68)
web/src/components/settings/PersonalSetting.jsx (2)
web/src/components/settings/personal/cards/CheckinCalendar.jsx (1)
CheckinCalendar(42-382)web/src/components/auth/LoginForm.jsx (3)
status(105-108)turnstileEnabled(71-71)turnstileSiteKey(72-72)
🔇 Additional comments (4)
router/api-router.go (1)
99-99: LGTM!The
TurnstileCheckmiddleware integration follows the established pattern used elsewhere (registration, login, email verification). The middleware correctly gates the check-in endpoint and leverages session-based caching to avoid repeated verification.web/src/components/settings/PersonalSetting.jsx (1)
454-459: LGTM!The
turnstileEnabledandturnstileSiteKeyprops are correctly passed toCheckinCalendar, following the same pattern used for other modals likeEmailBindModalandAccountDeleteModal. The props are properly derived from the status state.web/src/components/settings/personal/cards/CheckinCalendar.jsx (2)
228-239: LGTM!The Turnstile widget integration is well-implemented:
- Using
keyprop to force re-initialization on expiration is the correct pattern forreact-turnstileonVerifyproperly passes the token todoCheckinonExpirecorrectly refreshes the widget
42-46: LGTM!The component signature properly accepts the new Turnstile-related props, and the state management for modal visibility and widget key is correctly initialized.
…curity-check feat: check-in feature integrates Turnstile security check
…curity-check feat: check-in feature integrates Turnstile security check
…curity-check feat: check-in feature integrates Turnstile security check
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.