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): Extend client cookie lifetime #4312

Merged
merged 18 commits into from
Oct 29, 2024
Merged

Conversation

issuedat
Copy link
Member

@issuedat issuedat commented Oct 10, 2024

Description

  • Redirects the user to the /v1/client/touch endpoint to extend the __client cookie's lifetime when the cookie expiration <= 8 days
  • Deprecates beforeEmit in favor of passing a redirectUrl to setActive

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 Oct 10, 2024

🦋 Changeset detected

Latest commit: 0b873da

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

This PR includes changesets to release 18 packages
Name Type
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/elements Patch
@clerk/clerk-react Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/shared Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/themes 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

@issuedat issuedat changed the title USER-810: Extend client cookie lifetime fix(clerk-js): Extend client cookie lifetime Oct 10, 2024
@issuedat
Copy link
Member Author

!snapshot client-touch

@clerk-cookie
Copy link
Collaborator

Hey @issuedat - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.4.0-client-touch.v9ff6ce8
@clerk/backend 1.15.0-client-touch.v9ff6ce8
@clerk/chrome-extension 1.3.21-client-touch.v9ff6ce8
@clerk/clerk-js 5.28.0-client-touch.v9ff6ce8
@clerk/elements 0.17.0-client-touch.v9ff6ce8
@clerk/clerk-expo 2.2.27-client-touch.v9ff6ce8
@clerk/express 1.3.2-client-touch.v9ff6ce8
@clerk/fastify 2.0.4-client-touch.v9ff6ce8
@clerk/localizations 3.3.1-client-touch.v9ff6ce8
@clerk/nextjs 5.8.0-client-touch.v9ff6ce8
@clerk/clerk-react 5.12.1-client-touch.v9ff6ce8
@clerk/remix 4.2.40-client-touch.v9ff6ce8
@clerk/clerk-sdk-node 5.0.53-client-touch.v9ff6ce8
@clerk/shared 2.10.0-client-touch.v9ff6ce8
@clerk/tanstack-start 0.4.16-client-touch.v9ff6ce8
@clerk/testing 1.3.14-client-touch.v9ff6ce8
@clerk/themes 2.1.38-client-touch.v9ff6ce8
@clerk/types 4.27.0-client-touch.v9ff6ce8

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/clerk-sdk-node

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk clerk deleted a comment from clerk-cookie Oct 23, 2024
@issuedat issuedat marked this pull request as ready for review October 23, 2024 10:46
@issuedat issuedat requested a review from brkalow October 25, 2024 15:16
void context.clerk.setActive({ session, beforeEmit });
void context.clerk.setActive({
session,
redirectUrl: context.router?.searchParams().get('redirect_url') || context.clerk.buildAfterSignInUrl(),
Copy link
Member

Choose a reason for hiding this comment

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

@brkalow would this change the behavior of the AIO components? My understanding is that Clerk#navigate will use the routerPush/routerReplace functions passed to ClerkProvider so it should be okay, just want to verify that this is true for the AIO components as well.

Copy link
Member

Choose a reason for hiding this comment

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

It should be okay for this case 👍 will test

void context.clerk.setActive({ session, beforeEmit });
void context.clerk.setActive({
session,
redirectUrl: context.router?.searchParams().get('redirect_url') || context.clerk.buildAfterSignUpUrl(),
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

}) => {
if (typeof ctx.afterSelectPersonalUrl === 'function' && user) {
return navigate(ctx.afterSelectPersonalUrl(user));
return ctx.afterSelectPersonalUrl(user);
Copy link
Member

Choose a reason for hiding this comment

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

This does make sense to me, but before merging, I'd like to verify that the router the components use internally still updates its state after the setActive invocation.

To share a bit of context, even though the clerk-js components will use the router of the parent host for navigations (routerPush and routerReplace) they still hold an internal router state (clerk-js/src/ui/RouteContext). This state updates when navigate is called but after this change, the internal navigate invocation will be replaced by Clerk#navigate.

@issuedat apologies, I know the names are confusing here. Tagging @panteliselef as well as he's most likely interested in this as well.

packages/clerk-js/src/core/clerk.ts Outdated Show resolved Hide resolved
Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

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

This looks good to me! I left a few minor suggestions on moving some logic into Client.

Nice work.

packages/clerk-js/src/core/clerk.ts Outdated Show resolved Hide resolved
packages/clerk-js/src/core/clerk.ts Outdated Show resolved Hide resolved
@issuedat issuedat merged commit f875463 into main Oct 29, 2024
21 checks passed
@issuedat issuedat deleted the user-810-client-cookie-exp branch October 29, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants