-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix: add optional chainings to handleMiddleware function to avoid raising a TypeError #166
fix: add optional chainings to handleMiddleware function to avoid raising a TypeError #166
Conversation
…sing a TypeError
WalkthroughThe recent update enhances the robustness of the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/authMiddleware/authMiddleware.js (2 hunks)
Additional comments not posted (5)
src/authMiddleware/authMiddleware.js (5)
Line range hint
38-38
: Optional chaining added tooptions?.isReturnToCurrentPage
.This change ensures that the code handles cases where
options
might be undefined or null, preventing potential runtime errors.
Line range hint
39-39
: Optional chaining added tooptions?.loginPage
.This change ensures that the code handles cases where
options
might be undefined or null, preventing potential runtime errors.
Line range hint
43-45
: Optional chaining added tooptions?.publicPaths
.This change ensures that the code handles cases where
options
might be undefined or null, preventing potential runtime errors.
58-58
: Optional chaining added tooptions?.redirectURLBase
.This change ensures that the code handles cases where
options
might be undefined or null, preventing potential runtime errors.
88-88
: Optional chaining added tooptions?.redirectURLBase
.This change ensures that the code handles cases where
options
might be undefined or null, preventing potential runtime errors.
Oh, need this 🙏 |
…gs-to-middleware fix: add optional chainings to handleMiddleware function to avoid raising a TypeError
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:
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.