feat (packages/nhost-js): add decoded token to session storage#37
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 pull request enhances session storage by adding JWT token decoding with automatic conversion of timestamps and PostgreSQL array parsing. Key changes include updating type imports across modules, implementing a new session interface with decoded tokens, and updating tests and documentation accordingly.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/nhost-js/src/session/storageBackend.ts | Updated import for Session type to align with the new session module |
| packages/nhost-js/src/session/storage.ts | Invokes decoding of JWT token and stores the decoded token in session storage |
| packages/nhost-js/src/session/session.ts | Introduces new Session interface along with JWT token decoding logic |
| packages/nhost-js/src/session/refreshSession.ts | Refactors session refresh logic by leveraging the decoded token’s expiration time |
| Packages/nhost-js/src/nhost.ts and others | Adjusted imports to reference the updated Session type, with corresponding documentation updates |
| throw new Error("Invalid access token format"); | ||
| } | ||
|
|
||
| const decodedToken = JSON.parse(atob(s[1])) as Record<string, unknown>; |
There was a problem hiding this comment.
The use of atob may cause issues in non-browser environments (e.g. Node.js environments such as Next.js SSR). Consider adding a fallback using Buffer.from(..., 'base64').toString('utf8') when atob is not available.
| const decodedToken = JSON.parse(atob(s[1])) as Record<string, unknown>; | |
| const decodedToken = JSON.parse(decodeBase64(s[1])) as Record<string, unknown>; |
PR Type
Enhancement
Description
Add decoded JWT token to session storage
Convert timestamps to Date objects automatically
Parse PostgreSQL arrays in Hasura claims
Update documentation with new session interface
Changes walkthrough 📝
1 files
Add comprehensive test for decoded token functionality6 files
Update import to use session module typesExport Session type from session moduleUpdate imports to use session module typesAdd JWT decoding with timestamp and claims processingIntegrate token decoding into session storage operationsUpdate type imports to use session module3 files
Add reference to extended Session interfaceUpdate return type references to session moduleAdd comprehensive documentation for new Session interface