You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type Consistency The getFromBody function should ensure the type consistency of the return value. It currently returns undefined if the access_token is not a string, which might lead to type inconsistencies in getToken where the return type is expected to be a string. Consider returning an empty string if access_token is not valid.
Error Handling There is no error handling for malformed inputs in the getFromBody and getToken functions. Consider adding checks or try-catch blocks to handle potential errors gracefully, especially when dealing with external inputs.
✅ Add a test case to ensure getToken handles undefined headers and body correctly
Add a test case to verify that getToken returns an empty string when both headers and body are undefined, ensuring the function handles null inputs gracefully.
it("should return empty string if no token is found", () => {
const headers: HeadersLike = {};
expect(getToken({ headers, clientId })).toBe("");
});
+it("should return empty string if headers and body are undefined", () => {+ expect(getToken({ clientId })).toBe("");+});
[Suggestion has been applied]
Suggestion importance[1-10]: 9
Why: Adding this test case ensures that the function handles null inputs gracefully, which is crucial for robust testing and reliability.
9
✅ Ensure getToken function always returns a string by simplifying the return statement
Modify the getToken function to handle cases where fromBody, fromCookie, and fromHeader might all be undefined, to ensure the function always returns a string.
Why: Adding a null check for the body parameter is a good practice to prevent potential runtime errors when body is undefined. This enhances the robustness of the function.
8
Maintainability
Use a common token variable in test cases to reduce repetition and enhance maintainability
Refactor the test cases to use a common token string variable to avoid repetition and make the tests easier to maintain.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
BREAKING CHANGE: the params are now an object
PR Type
Enhancement, Tests
Description
getToken
function to support token extraction from the request body.BodyLike
type definition to represent the request body structure.getToken
.Changes walkthrough 📝
getToken.test.ts
Add and update tests for getToken function enhancements
packages/auth-common/src/components/tests/getToken.test.ts
header.
getToken.ts
Enhance getToken function to support token extraction from body
packages/auth-common/src/components/getToken.ts
BodyLike
type definition.getToken
function to accept body parameter.