-
Notifications
You must be signed in to change notification settings - Fork 22
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
refreshSession #594
base: main
Are you sure you want to change the base?
refreshSession #594
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9a96833:
|
} | ||
|
||
const timeUntilExpiry = expiryTime - Date.now(); | ||
const warningThreshold = SESSION_WARNING_THRESHOLD_SECONDS * 1000; |
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.
Would be cool to optionally pass in a threshold here. But not blocking
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.
will note this down for next release - for now going to skip this as its a bit of work to do since we need to then store it along with the session in secure storage (which would a lot of testing)
newPrivateKey, | ||
config.apiBaseUrl, | ||
); | ||
const user = await fetchUser(newClient, config.organizationId); |
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.
You could do a simple getWhoAmI here, not blocking
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.
this is a helper function to basically do that - for RN i decided to have the wallet and wallet accounts in the user object because I thought it made things easier. We also store the user in the session object that way we don't have to keep making requests every time a user leaves the app (the useEffect runs)
}; | ||
|
||
// if selected session is being refreshed, we update the local state session and client | ||
if (session?.key === keyToRefresh) { |
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.
Will this ever not be true? the sessions key
is set to keyToRefresh
right above here
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.
I believe here we are checking the local state variable (currently selected session) session key - not the new one we just created (the one above). Honestly I should probably write a doc on how this all works - theres a lot of things going on
Summary & Motivation
client asked for abstraction to be able to refresh sessions before they expire (i.e extend the session)
went a step up and also added a warning function that runs 15 seconds before the session expiries - to make these an even easier process
How I Tested These Changes
Did you add a changeset?
If updating one of our packages, you'll likely need to add a changeset to your PR. To do so, run
pnpm changeset
.pnpm changeset
will generate a file where you should write a human friendly message about the changes. Note how this (example) includes the package name (should be auto added by the command) along with the type of semver change (major.minor.patch) (which you should set).These changes will be used at release time to determine what packages to publish and how to bump their version. For more context see this comment.