Skip to content

[FEAT] Add minSecondsBeforeRefresh + debounce refresh token - #43

Open
itailevi98 wants to merge 6 commits into
mainfrom
feat/access-token-updates
Open

[FEAT] Add minSecondsBeforeRefresh + debounce refresh token#43
itailevi98 wants to merge 6 commits into
mainfrom
feat/access-token-updates

Conversation

@itailevi98

@itailevi98 itailevi98 commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

Done as part of: https://www.notion.so/Client-Library-Updates-11753e303ce68051abf0cf4d570ee98e

Background

The original behavior before these changes was that in an application, on page focus, the /userinfo endpoint would be called each time. This was unnecessary, and would spam these network calls. Now, a user can pass in a prop minSecondsBeforeRefresh that will only call the endpoint after that time has passed. This logic is the same as in the JS library.

As well as this, a new function was added to get the user and access token form the server.

Smoke Tests

  • When not passing in a prop, and clicking around the page, the refresh only happens after the expiration time has passed.
  • When passing in a prop of 5 seconds, the /userinfo endpoint only gets called after those seconds are up, and after clicking on the page to focus it.
  • In the server, the getuserAndAccessToken function returned botht he user and access token as expected.

Comment thread src/server/app-router.ts Outdated
return undefined
}

export async function getUserAndAccessToken(): Promise<{ user?: UserFromToken; accessToken?: string }> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this type so they are either both set or both unset?

Comment thread src/server/app-router.ts Outdated
accessToken: string
}
| {
user: never

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be undefined

Comment thread src/client/AuthProvider.tsx Outdated
// If we were offline or on a different tab, when we return, refetch auth info
// Some browsers trigger focus more often than we'd like, so we'll debounce a little here as well
const refreshOnOnlineOrFocus = async function () {
if (lastRefresh && currentTimeSecs() > lastRefresh + minSecondsBeforeRefresh) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still refresh in the case where lastRefresh is undefined to be safe

@andrew-propelauth andrew-propelauth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants