-
Notifications
You must be signed in to change notification settings - Fork 13
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
Prevent unneeded calls to token endpoint #72
Conversation
WalkthroughThe recent updates enhanced the authentication flow in the Changes
Sequence Diagram(s)Updated Refresh Token LogicsequenceDiagram
participant Client
participant localStorage
participant Cookie
participant API
Client->>localStorage: Get localStorageRefreshToken
alt localStorageRefreshToken exists
Client->>API: Fetch new token using localStorageRefreshToken
else
Client->>Cookie: Check if '_kbrte' cookie exists (hasCookie)
alt Cookie exists
Client->>API: Fetch new token using '_kbrte' cookie
else
Note right of Client: No token available
end
end
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: 2
Outside diff range and nitpick comments (1)
src/utils/hasCookie/hasCookie.ts (1)
1-5
: Consider renaming the function for clarity.The function name
hasCookie
suggests a boolean return value, but the function returns the cookie's value. A more descriptive name, such asgetCookieValue
, would improve clarity.- const hasCookie = (name: string) => + const getCookieValue = (name: string) =>
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/createKindeClient.ts (3 hunks)
- src/utils/hasCookie/hasCookie.ts (1 hunks)
Additional comments not posted (4)
src/createKindeClient.ts (4)
4-4
: LGTM! Import statement is correct.The
hasCookie
function import is correctly added.
165-165
: LGTM! Variable renaming improves clarity.Renaming
refresh_token
tolocalStorageRefreshToken
enhances readability and aligns with the new logic.
169-170
: LGTM! Updated condition is correct.The updated condition to check for
localStorageRefreshToken
or the_kbrte
cookie usinghasCookie
is correctly implemented.
186-187
: LGTM! Fetch body object spread change is correct.The fetch body object spread now correctly uses
localStorageRefreshToken
.
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/utils/hasCookie/hasCookie.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/utils/hasCookie/hasCookie.ts
Explain your changes
For custom domains we store the refresh token in a secure, httpOnly cookie which cannot be read by client-side JavaScript. The upshot of this is that we optimistically called the token endpoint causing unnecessary additional requests.
We now added an additional cookie containing no sensitive data that essentially is a flag to indicate the presence of the refresh token cookie so we only call the token endpoint when this exists
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.