Skip to content

Conversation

@itailevi98
Copy link
Contributor

@itailevi98 itailevi98 commented Oct 8, 2024

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.

return undefined
}

export async function getUserAndAccessToken(): Promise<{ user?: UserFromToken; accessToken?: string }> {
Copy link
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?

accessToken: string
}
| {
user: never
Copy link
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

// 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
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

Copy link
Contributor

@andrew-propelauth andrew-propelauth left a comment

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.

3 participants