Open peterphanouvong opened 2 months ago
The changes in the pull request enhance the authentication middleware by introducing TypeScript type annotations and improving its configurability. The authMiddleware
function now accepts a NextRequest
type, and the handleMiddleware
function has been updated to accept optional parameters, including a structured options
object. A new isAuthorized
function is added for custom authorization logic. Additionally, the withAuth
function is refactored for better flexibility, and a new KindeRequest
type is introduced to extend NextRequest
.
File | Change Summary |
---|---|
src/authMiddleware/authMiddleware.ts |
- Modified authMiddleware to accept NextRequest . - Updated handleMiddleware to accept optional parameters and a structured options object. - Added KindeRequest type extending NextRequest with kindeAuth property. - Refactored withAuth for flexible request handling. |
Objective | Addressed | Explanation |
---|---|---|
Improve type safety in middleware (undefined) | ✅ | |
Enhance configurability of middleware (undefined) | ✅ |
withAuth
function, which is also enhanced in the main PR, indicating a direct connection in the authentication middleware functionality.src/authMiddleware/authMiddleware.ts (4)
Line range hint `10-32`: **LGTM!** The `authMiddleware` function has been correctly updated to accept a `NextRequest` type for the `request` parameter, improving type safety. The function logic is correct and the `trimTrailingSlash` helper function is correctly implemented. --- `35-48`: **The updated function signature looks good!** The `handleMiddleware` function has been correctly updated to accept optional parameters, including a more structured `options` object and an `onSuccess` callback. This improves flexibility and configurability of the middleware. --- `123-141`: **The `withAuth` function looks good!** The function has been correctly updated to handle both a request object and a middleware function more flexibly. The `KindeRequest` type is correctly defined and enhances the structure of the request object. The function uses the `handleMiddleware` function, which has been reviewed and approved with a verification request. --- `77-82`: **Verify the `isTokenValid` function usage.** The `isTokenValid` utility function is used for token validation, but its implementation is not provided in the context. Please ensure that this function is correctly implemented and handles token validation as expected. Run the following script to verify the function usage:
Explain your changes
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.