-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add useAccessToken and useTokenClaims hooks #63
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR adds new hooks to manage access tokens and extract token claims, while updating exports and type imports for better type management.
- Added useAccessToken for token management with automatic refresh and error handling.
- Added useTokenClaims to extract token claims in a type-safe manner.
- Updated index exports and refined type imports in state.ts.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/state.ts | Changed the import of the User type to a type-only import for improved dependency usage. |
src/index.ts | Exported the new hooks useAccessToken and useTokenClaims. |
src/accessToken.ts | Added new hooks for access token handling including refresh logic and token claims parsing. |
package.json | Updated the @workos-inc/authkit-js dependency version to 0.12.0. |
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.
we already have logic in authkit-react/authkit-js to manage the refresh
* | ||
* @returns An object containing the access token, loading state, error state, and a refresh function. | ||
*/ | ||
export function useAccessToken() { |
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.
the traditional way to get claims in authkit-react is via the useAuth
hook. i think we should just extend that to support custom claims instead of bolting on a new hook.
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.
So, I was looking to bring closer parity to authkit-nextjs, having the same hooks in workos/authkit-nextjs#258 plus having a cleaner separation of concerns.
Note
This is dependent on workos/authkit-js#87.
This pull request introduces new functionality for managing access tokens with automatic refresh and token claims extraction, alongside minor improvements to type imports and exports. The most significant changes include the addition of the
useAccessToken
anduseTokenClaims
hooks, updates to thesrc/index.ts
exports, and a refinement in type usage for theUser
interface.New functionality for access tokens:
src/accessToken.ts
: Added theuseAccessToken
hook to manage access tokens with automatic refresh and error handling. It includes a reducer for token state management and utility functions for token parsing and refresh logic.src/accessToken.ts
: Added theuseTokenClaims
hook to extract claims from access tokens, enabling developers to access custom claims in a type-safe manner.Updates to exports:
src/index.ts
: Exported the newly addeduseAccessToken
anduseTokenClaims
hooks to make them available for use in other parts of the application.Type improvements:
src/state.ts
: Changed the import of theUser
type from a regular import to atype
import for better type-only dependency management.