Allow SWR mutation in useUser hook#2045
Merged
tusharpandey13 merged 10 commits intomainfrom Apr 25, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2045 +/- ##
==========================================
+ Coverage 78.47% 80.02% +1.55%
==========================================
Files 21 21
Lines 1909 1907 -2
Branches 307 315 +8
==========================================
+ Hits 1498 1526 +28
+ Misses 405 376 -29
+ Partials 6 5 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
frederikprijck
previously requested changes
Apr 7, 2025
This has been taken care of
There was a problem hiding this comment.
Pull Request Overview
This PR adds an invalidate function to the useUser hook to allow clients to manually trigger a SWR revalidation of the user profile. In addition, the PR includes various style and formatting improvements and updates to related tests to ensure full coverage of the new functionality.
- Added an invalidate method to the useUser hook.
- Updated both unit and integration tests to verify the correct behavior of invalidate.
- Made minor formatting and code style adjustments across several session and auth client files.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/server/session/stateless-session-store.ts | Refactored import and formatting of cookie decryption and cookie deletion. |
| src/server/session/stateless-session-store.test.ts | Updated cookie name quoting and test formatting for clarity. |
| src/server/session/stateful-session-store.test.ts | Cleaned up extra whitespace and standardized argument ordering. |
| src/server/cookies.ts | Simplified arrow function syntax while preserving functionality. |
| src/server/auth-client.ts | Reordered some error imports and formatted promise return type declarations. |
| src/server/auth-client.test.ts | Adjusted bracket notation for property access and test callback formatting. |
| src/client/hooks/use-user.unit.test.tsx | Added unit tests to cover the new invalidate functionality and revised SWR mocks. |
| src/client/hooks/use-user.ts | Extended useUser to include invalidate using mutate and re-ordered error/data checks. |
| src/client/hooks/use-user.integration.test.tsx | Introduced integration tests to validate re-fetch behavior and error handling on invalidate. |
nandan-bhat
approved these changes
Apr 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #1937
Changes
invalidatefunction to the return value of theuseUserhook./auth/profileendpoint.Testing
Tests have been updated in
src/client/hooks/use-user.test.tsxto cover the newinvalidatefunctionality, ensuring it correctly triggers a data refresh using SWR'smutatefunction.PASSING
Usage
Client Components:
You can access the
invalidatefunction from theuseUserhook and call it when you need to refresh the user data, for example, after a user profile update action.