-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logout API #10416
Logout API #10416
Conversation
WalkthroughThis pull request enhances the logout process. The changes in the authentication provider add new imports and update the Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant Provider as AuthUserProvider
participant API as API Module
participant Storage as Local Storage
User->>Provider: Initiate signOut
Provider->>API: Call mutate(logout, {accessToken, refreshToken})
alt Successful API Response
API-->>Provider: Logout success
else API Error
API-->>Provider: Return error
Provider->>Console: Log error
end
Provider->>Storage: Remove tokens
Provider->>QueryClient: Reset queries
Poem
Tip 🌐 Web search-backed reviews and chat
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Deploying care-fe with
|
Latest commit: |
5f3855f
|
Status: | ✅ Deploy successful! |
Preview URL: | https://315a2698.care-fe.pages.dev |
Branch Preview URL: | https://logout.care-fe.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/Providers/AuthUserProvider.tsx (1)
88-102
: Consider enhancing error handling and token validation.While the error handling is present, there are a few improvements that could be made:
- Validate tokens before attempting to call the logout API
- Handle specific error types differently
- Consider notifying the user of logout failures
Consider this enhanced implementation:
const signOut = useCallback(async () => { const accessToken = localStorage.getItem(LocalStorageKeys.accessToken); const refreshToken = localStorage.getItem(LocalStorageKeys.refreshToken); - if (accessToken && refreshToken) { + if (!accessToken || !refreshToken) { + console.warn("No tokens found during logout"); + } else { try { await mutate({ ...routes.logout, TRes: Type<Record<string, never>>(), })({ access: accessToken, refresh: refreshToken }); } catch (error) { - console.error("Error during logout:", error); + // Log the error but don't block the logout process + console.error("Error during remote logout:", error); + // Optionally notify the user + // toast.warning("Error during logout, but your session was cleared locally"); } }src/Utils/request/api.tsx (2)
106-110
: Consider adding noAuth flag for consistency.The logout route definition looks good, but for consistency with other auth-related routes (like login), consider adding the
noAuth
flag. This ensures the request won't fail if the token is already invalidated server-side.Apply this change:
logout: { path: "/api/v1/auth/logout/", method: "POST", + noAuth: true, TBody: Type<JwtTokenObtainPair>(), },
106-110
: Add TRes type for better type safety.The route is missing the TRes type definition, which is present in most other routes. This helps ensure type safety for the response handling.
Apply this change:
logout: { path: "/api/v1/auth/logout/", method: "POST", TBody: Type<JwtTokenObtainPair>(), + TRes: Type<Record<string, never>>(), },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Providers/AuthUserProvider.tsx
(2 hunks)src/Utils/request/api.tsx
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Test
- GitHub Check: OSSAR-Scan
- GitHub Check: cypress-run (1)
- GitHub Check: CodeQL-Build
- GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (1)
src/Providers/AuthUserProvider.tsx (1)
12-13
: LGTM!The new imports are correctly added and align with the updated signOut functionality.
@amjithtitus09 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌 |
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
New Features
Refactor