Closed DanielRivers closed 1 month ago
This pull request updates the authentication logic by replacing the jwt_decode
function with jwtDecoder
from the @kinde/jwt-decoder
package across multiple files. The modifications streamline the handling of access and ID tokens, enhance type safety, and simplify the decoding process. Method signatures and import statements have been updated accordingly to reflect these changes, ensuring consistency and clarity in the authentication middleware and related functions.
File(s) | Change Summary |
---|---|
src/authMiddleware/authMiddleware.ts, src/handlers/setup.ts | Replaced jwt_decode with jwtDecoder , updated method signatures, and adjusted handling logic. |
src/session/getAccessToken.js, src/session/getIdToken.js, | Replaced jwt_decode with jwtDecoder , updated method signatures, and adjusted handling logic. |
src/session/getUser.ts, src/session/getUserOrganizations.ts, | Replaced jwt_decode with jwtDecoder , updated method signatures, and adjusted handling logic. |
src/session/isAuthenticated.js, src/utils/pageRouter/isTokenValid.js | Replaced jwt_decode with jwtDecoder , updated method signatures, and adjusted handling logic. |
isTokenValid
function, which is directly related to the changes made in the main PR regarding the authentication logic and token handling.isAuthenticated
property from the useKindeAuth
hook, which is relevant to the overall authentication process that the main PR updates.createKindeManagementAPIClient
function, which aligns with the updates made in the main PR regarding token validity and management.src/authMiddleware/authMiddleware.ts (5)
`4-5`: **LGTM: Improved imports and type definitions** The changes to the import statements align well with the PR objectives. Replacing `jwt-decode` with `@kinde/jwt-decoder` and importing specific types (`KindeAccessToken` and `KindeIdToken`) from a local types file should improve type safety and maintainability. --- `16-16`: **LGTM: Simplified authentication check** The updated `isAuthenticated` check using `isTokenValid(kinde_token?.value)` is a good improvement. It simplifies the logic and aligns with the PR objectives of enhancing token validation. The use of optional chaining is also a good practice to prevent potential errors if the token is undefined. --- `60-65`: **LGTM: Improved token decoding with better type safety** The changes in this segment are excellent: 1. Replacing `jwt_decode` with `jwtDecoder` aligns with the PR objectives. 2. Adding type parameters (`KindeAccessToken` and `KindeIdToken`) improves type safety. 3. Using optional chaining (`?.`) for both `access_token` and `id_token` addresses potential undefined values, resolving a previous review comment. These updates enhance the overall robustness and type safety of the token handling process. --- `100-100`: _:warning: Potential issue_ **Address TypeScript error instead of using @ts-ignore** The `@ts-ignore` comment is still present, which was flagged in a previous review. It's important to address the underlying TypeScript error rather than suppressing it. This ensures better type safety and helps prevent potential runtime issues. Could you please investigate the cause of the TypeScript error and resolve it? If you need assistance, I'd be happy to help identify and fix the issue. --- `117-117`: _:warning: Potential issue_ **Resolve TypeScript error instead of using @ts-ignore** Similar to the previous instance, the `@ts-ignore` comment remains here as well. It's crucial to address the root cause of the TypeScript error rather than suppressing it with `@ts-ignore`. This ensures better type safety and helps maintain a robust codebase. Please investigate and resolve the underlying TypeScript error. If you need any assistance in identifying or fixing the issue, feel free to ask.
Explain your changes
This replaces
jwt-decode
with@kinde/jwt-decoder
Added token validation check to the isAuthenticated method Added token validation check to the authMiddlewareChecklist
🛟 If you need help, consider asking for advice over in the Kinde community.