Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

refreshSession #594

wants to merge 4 commits into from

Conversation

moeodeh3
Copy link
Contributor

@moeodeh3 moeodeh3 commented Apr 11, 2025

Summary & Motivation

client asked for abstraction to be able to refresh sessions before they expire (i.e extend the session)

image

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.

Copy link

vercel bot commented Apr 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
sdk-email-auth ⬜️ Skipped (Inspect) Apr 14, 2025 3:27pm
sdk-otp-auth ⬜️ Skipped (Inspect) Apr 14, 2025 3:27pm

Copy link

codesandbox-ci bot commented Apr 11, 2025

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:

Sandbox Source
@turnkey/example-react-components Configuration

}

const timeUntilExpiry = expiryTime - Date.now();
const warningThreshold = SESSION_WARNING_THRESHOLD_SECONDS * 1000;
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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

@vercel vercel bot temporarily deployed to Preview – sdk-otp-auth April 14, 2025 15:27 Inactive
@vercel vercel bot temporarily deployed to Preview – sdk-email-auth April 14, 2025 15:27 Inactive
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