fix(socket): use core auth user id for socket state scoping#1984
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSocket service now derives the current user ID from CoreStateProvider snapshot auth state instead of unverified client-side JWT decoding. getSocketUserId() reads snapshot.auth.userId and falls back to 'pending'. Tests updated to mock snapshot.auth.userId and verify socket operations use the core auth userId. ChangesSocket Service Auth State Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/services/socketService.ts`:
- Line 96: The current return expression directly dereferences
getCoreStateSnapshot().snapshot.auth.userId so if snapshot or auth is undefined
the access will throw and the '__pending__' fallback won't run; update the
access in socketService.ts to guard the nested path with optional chaining
(e.g., use snapshot?.auth?.userId) when retrieving the userId from
getCoreStateSnapshot() so the nullish fallback is honored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d3876ff6-5f74-48fe-8f3f-17cb69231ce0
📒 Files selected for processing (3)
app/src/services/__tests__/socketService.events.test.tsapp/src/services/__tests__/socketService.test.tsapp/src/services/socketService.ts
Summary
socketService.Problem
socketServicedecodedsessionTokenwithatob()to derive a socket user ID.Solution
getSocketUserId()to usegetCoreStateSnapshot().snapshot.auth.userId ?? '__pending__'.auth.userId.Submission Checklist
## Related- N/A: no coverage-matrix feature row affected.Closes #NNNin the## RelatedsectionImpact
Related
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
fix/1942-socket-user-id-from-core-state1801d215Validation Run
pnpm --filter openhuman-app format:checkpnpm typecheckpnpm.cmd --dir app exec vitest run --config test/vitest.config.ts src/services/__tests__/socketService.test.ts src/services/__tests__/socketService.events.test.tscargo fmt --manifest-path ../Cargo.toml --all --checkcargo fmt --manifest-path src-tauri/Cargo.toml --all --checkcargo check --manifest-path src-tauri/Cargo.tomlcargo fmt --manifest-path src-tauri/Cargo.toml --all --checkcargo check --manifest-path src-tauri/Cargo.tomlValidation Blocked
command:N/Aerror:N/Aimpact:N/ABehavior Changes
Parity Contract
__pending__when no core auth user ID is available; focused tests cover socket connection and event dispatch behavior.Duplicate / Superseded PR Handling
Summary by CodeRabbit