fix (packages/nhost-js): if session doesn't have decodedToken treat as expired#49
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in session handling where sessions without a decodedToken were incorrectly treated as valid instead of expired. The fix ensures that sessions missing valid decoded tokens are properly marked as expired and in need of refresh.
- Changed session validation logic to treat missing decodedToken as expired
- Modified return values to indicate refresh is needed for invalid token sessions
- Added explanatory comments for the logic change
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return { session: null, needsRefresh: false, sessionExpired: false }; | ||
| // if the session does not have a valid decoded token, treat it as expired | ||
| // as we can't determine its validity | ||
| return { session: session, needsRefresh: true, sessionExpired: true }; |
There was a problem hiding this comment.
[nitpick] The variable name 'session' is redundant in the object property assignment. Consider using shorthand property notation: return { session, needsRefresh: true, sessionExpired: true };
| return { session: session, needsRefresh: true, sessionExpired: true }; | |
| return { session, needsRefresh: true, sessionExpired: true }; |
PR Type
Bug fix
Description
Fix session handling for missing decoded tokens
Treat sessions without decodedToken as expired
Return needsRefresh=true for invalid token sessions
Improve session validation logic
Diagram Walkthrough
File Walkthrough
refreshSession.ts
Fix session validation for missing decoded tokenspackages/nhost-js/src/session/refreshSession.ts
_needsRefreshfunction to handle missing decodedToken