fix: extract withAuth() guard and standardize auth checks in Server Actions#89
Conversation
…ctions Closes #63 - Created `src/lib/actions/auth-guard.ts` with reusable `withAuth` HOF that handles Supabase client creation + user authentication in one place - Wrapped 16 mutating Server Actions that previously had no auth check: - board.ts: 8 functions (updateStatusList, updateStatusListPosition, swapStatusListPositions, batchUpdateStatusListPositions, updateRepoCardPosition, batchUpdateRepoCardOrders, deleteBoard, updateBoard) - project-info.ts: 4 functions (upsertProjectInfo, updateComment, updateCommentColor, deleteComment) - maintenance-project-info.ts: 4 functions (upsertMaintenanceProjectInfo, updateMaintenanceComment, updateMaintenanceCommentColor, deleteMaintenanceComment) - Input validation stays outside withAuth (fail-fast before auth overhead) - Functions that already had explicit auth checks were left unchanged
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
🤖 Morph Preview Test⚡ Looks like you hit your rate limits! Please upgrade your limits here, or wait a few minutes and try again. If you need help, reach out to support@morphllm.com. Automated testing by Morph |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #89 +/- ##
=======================================
Coverage 74.33% 74.33%
=======================================
Files 119 119
Lines 3873 3873
Branches 1062 1030 -32
=======================================
Hits 2879 2879
Misses 971 971
Partials 23 23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🧪 E2E Coverage Report (Sharded: 12 parallel jobs)
📊 Full report available in workflow artifacts |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
🤖 Morph Preview Test⚡ Looks like you hit your rate limits! Please upgrade your limits here, or wait a few minutes and try again. If you need help, reach out to support@morphllm.com. Automated testing by Morph |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/actions/board.ts (1)
943-1045:⚠️ Potential issue | 🟠 Major
updateBoardSettingsActionis a mutating action with no auth check.This action writes to the
boardtable (line 1032–1035) but never verifies the user is authenticated — it callscreateClient()directly at line 975 with nogetUser()orwithAuth. Every other mutating board action now has an explicit auth guard. This one was likely overlooked.Consider wrapping the DB read+write portion with
withAuth, or at minimum adding agetUser()check before the mutations, consistent with the rest of this file.
Summary
Closes #63
withAuth()higher-order function insrc/lib/actions/auth-guard.tsthat wraps Server Actions with Supabase authentication, eliminating repeated 4-line auth boilerplatewithAuthto 16 mutating Server Actions across 3 files that previously had no authentication check:board.ts(8 functions): updateStatusList, updateStatusListPosition, swapStatusListPositions, batchUpdateStatusListPositions, updateRepoCardPosition, batchUpdateRepoCardOrders, deleteBoard, updateBoardproject-info.ts(4 functions): upsertProjectInfo, updateComment, updateCommentColor, deleteCommentmaintenance-project-info.ts(4 functions): upsertMaintenanceProjectInfo, updateMaintenanceComment, updateMaintenanceCommentColor, deleteMaintenanceCommentwithAuth(fail-fast before auth overhead)createBoard,toggleBoardFavorite) were left unchangedTest plan
pnpm typecheckpassespnpm lintpasses (zero warnings)pnpm buildsucceedspnpm test— all 85 test files / 1202 tests passSummary by CodeRabbit