Closed Seagull29 closed 1 month ago
The recent update enhances the robustness of the handleMiddleware
function in the authMiddleware.js
file. By incorporating optional chaining (?.
), the code now safely accesses the redirectURLBase
property within the options
object. This prevents potential errors when options
is undefined or null, ensuring smoother execution and more reliable URL redirection logic.
Files | Change Summary |
---|---|
src/.../authMiddleware.js |
Updated to use optional chaining (?. ) when accessing redirectURLBase in the handleMiddleware function. |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Oh, need this 🙏
Adding optional chainings to avoid raising a TypeError
Since the commit 817d1b3 that was uploaded a day ago, a TypeError appeared with a simple setup of a Nextjs project and this library, specifically, by using the withAuth middleware which is used to protect routes.
The error was the following:![image](https://github.com/kinde-oss/kinde-auth-nextjs/assets/54561501/072f8628-f602-48d1-8579-7e2ad88a317e)
By seeing the changes made, it seems the redirectURLBase is indeed being read from an object that may be undefined; therefore, it only raises that error by using the middleware, at least, with a simple setup and use of withAuth middleware. The variable option is not always passed to the handleMiddleware, so that is why and where the error happens.
While these changes can fix the issue, perhaps other features were trying to be implemented with the usage of the variable options, so I'm not sure whether the variable options is mandatory across the global context of the project. However, since prior commits do not have that variable, I believe adding the optional chainings is enough to solve the issue as they are properly written on the same function on the lines that use the variable options.
For the record, within the handleMiddleware function, the optional chainings were missing on both return statements.
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.