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

Reduce access token refreshing if it is still fresh #22464

Merged
merged 4 commits into from May 14, 2024

Conversation

licitdev
Copy link
Member

@licitdev licitdev commented May 10, 2024

Scope

What's changed:

  • Reimplemented the skipping of access token refresh logic while it is still fresh

Potential Risks / Drawbacks

  • Should not have any as the access token generally should remain valid up till its expiry

Review Notes / Questions

directus/app/src/auth.ts

Lines 99 to 105 in 77d7339

// Skip refresh if access token is still fresh
if (appStore.accessTokenExpiry && Date.now() < appStore.accessTokenExpiry - 10000) {
// Set a fresh timeout as it is cleared by idleTracker's idle or hide event
clearTimeout(refreshTimeout);
refreshTimeout = setTimeout(() => refresh(), appStore.accessTokenExpiry - 10000 - Date.now());
return;
}

Copy link

changeset-bot bot commented May 10, 2024

🦋 Changeset detected

Latest commit: d40a652

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@directus/app Patch
@directus/api Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

app/src/auth.ts Outdated Show resolved Hide resolved
@licitdev licitdev force-pushed the reduce-refreshing-while-fresh branch from 183e892 to 1f4ac44 Compare May 13, 2024 11:42
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Copy link
Contributor

@hanneskuettner hanneskuettner left a comment

Choose a reason for hiding this comment

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

Nice fix! 🎸

I've verified with a short session cookie duration that both the SDK triggered refresh and the tab active refresh work as expected, and otherwise the /users/me endpoint is called.

.changeset/bright-trains-greet.md Outdated Show resolved Hide resolved
Co-authored-by: Hannes Küttner <4376726+hanneskuettner@users.noreply.github.com>
@paescuj paescuj merged commit 2ecee4e into main May 14, 2024
4 checks passed
@paescuj paescuj deleted the reduce-refreshing-while-fresh branch May 14, 2024 08:03
@github-actions github-actions bot added this to the Next Release milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants