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

fix(clerk-js): Set __session and __client_uat before invalidating cache #3774

Merged
merged 3 commits into from
Jul 22, 2024

Conversation

nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Jul 19, 2024

Description

Fixes the following flow that mainly affected nextjs apps:

Setup:

  • Dev instance
  • Latest next, clerk/nextjs and clerk-js
  • Multi-app-same-domain FF disabled
    Steps:
  • Go to app
  • Enter email and hit continue (signIn.create): client_uat is 0
  • Enter password and hit continue (signIn.attemptFirstFactor) : client_uat > 0 (for accounts)
  • Clerk-js invalidates cache : client_uat is 0 because clerk-js does not set it correctlly

The main issue in the clerk-js codebase was that during sign-in/sign-up, we set the cookies implicitly when we update the current Client resource (Base -> updateClient -> Client.fromJson() -> new Session -> hydrate token cache). However, the Clerk.client only gets updated AFTER the token cache is hydrated, so setting the client_uat token failed because when it runs, Clerk.client.activeSessions is still 0 (its still the previous value)

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Jul 19, 2024

🦋 Changeset detected

Latest commit: 55f46af

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

This PR includes changesets to release 4 packages
Name Type
@clerk/clerk-js Patch
@clerk/astro Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo 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

@nikosdouvlis nikosdouvlis force-pushed the nikos/set-cookies-before-invalidate branch from bb75f0e to 60e73bf Compare July 22, 2024 09:15
@nikosdouvlis nikosdouvlis force-pushed the nikos/set-cookies-before-invalidate branch from 60e73bf to cb272e0 Compare July 22, 2024 09:55
@nikosdouvlis nikosdouvlis force-pushed the nikos/set-cookies-before-invalidate branch from ec0d177 to 78d9460 Compare July 22, 2024 10:08
@nikosdouvlis nikosdouvlis force-pushed the nikos/set-cookies-before-invalidate branch from 78d9460 to bb3771e Compare July 22, 2024 10:45
@nikosdouvlis nikosdouvlis merged commit c5d0152 into main Jul 22, 2024
16 checks passed
@nikosdouvlis nikosdouvlis deleted the nikos/set-cookies-before-invalidate branch July 22, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants