Skip to content

fix(backend): Fix getToken returning null when resolving the handshake payload - #3764

Merged
anagstef merged 4 commits into
mainfrom
stefanos/eco-51-gettoken-null-in-production
Jul 23, 2024
Merged

fix(backend): Fix getToken returning null when resolving the handshake payload#3764
anagstef merged 4 commits into
mainfrom
stefanos/eco-51-gettoken-null-in-production

Conversation

@anagstef

@anagstef anagstef commented Jul 19, 2024

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue on Remix where getToken() returns no token when redirecting back when sign-in and handshake are triggered.

The issue exists because the getToken() is getting the session token from the request cookie, but when returning from an external sign-in page (e.g. OAuth or Account Portal) on the request there is still the __clerk_handshake cookie, because it's not yet resolved. The issue exists only on production, and also does not happen to nextjs, because middleware has already resolved the handshake.

With this PR we pass the session token that exists inside the handshake payload to be returned when calling getToken().

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:

@anagstef anagstef self-assigned this Jul 19, 2024
@changeset-bot

changeset-bot Bot commented Jul 19, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cbde650

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

This PR includes changesets to release 9 packages
Name Type
@clerk/backend Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/tanstack-start Patch
@clerk/testing 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

@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

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

Package Version
@clerk/astro 1.0.1-snapshot.v7ada807
@clerk/backend 1.4.0-snapshot.v7ada807
@clerk/chrome-extension 1.1.5-snapshot.v7ada807
@clerk/clerk-js 5.10.0-snapshot.v7ada807
@clerk/elements 0.10.5-snapshot.v7ada807
@clerk/clerk-expo 1.2.8-snapshot.v7ada807
@clerk/express 0.0.18-snapshot.v7ada807
@clerk/fastify 1.0.20-snapshot.v7ada807
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/nextjs 5.2.5-snapshot.v7ada807
@clerk/clerk-react 5.2.9-snapshot.v7ada807
@clerk/remix 4.2.4-snapshot.v7ada807
@clerk/clerk-sdk-node 5.0.17-snapshot.v7ada807
@clerk/shared 2.4.0-snapshot.v7ada807
@clerk/tanstack-start 0.1.8-snapshot.v7ada807
@clerk/testing 1.1.12-snapshot.v7ada807

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

npm i @clerk/astro@1.0.1-snapshot.v7ada807 --save-exact

@clerk/backend

npm i @clerk/backend@1.4.0-snapshot.v7ada807 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.1.5-snapshot.v7ada807 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.10.0-snapshot.v7ada807 --save-exact

@clerk/elements

npm i @clerk/elements@0.10.5-snapshot.v7ada807 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.2.8-snapshot.v7ada807 --save-exact

@clerk/express

npm i @clerk/express@0.0.18-snapshot.v7ada807 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.20-snapshot.v7ada807 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.2.5-snapshot.v7ada807 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.2.9-snapshot.v7ada807 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.4-snapshot.v7ada807 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.17-snapshot.v7ada807 --save-exact

@clerk/shared

npm i @clerk/shared@2.4.0-snapshot.v7ada807 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.1.8-snapshot.v7ada807 --save-exact

@clerk/testing

npm i @clerk/testing@1.1.12-snapshot.v7ada807 --save-exact

@anagstef
anagstef force-pushed the stefanos/eco-51-gettoken-null-in-production branch from 7ada807 to 94b1fb2 Compare July 22, 2024 09:28
@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

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

Package Version
@clerk/astro 1.0.1-snapshot.v94b1fb2
@clerk/backend 1.4.0-snapshot.v94b1fb2
@clerk/chrome-extension 1.1.5-snapshot.v94b1fb2
@clerk/clerk-js 5.10.0-snapshot.v94b1fb2
@clerk/elements 0.10.5-snapshot.v94b1fb2
@clerk/clerk-expo 1.2.8-snapshot.v94b1fb2
@clerk/express 0.0.18-snapshot.v94b1fb2
@clerk/fastify 1.0.20-snapshot.v94b1fb2
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.5.0-snapshot.v94b1fb2
@clerk/nextjs 5.2.5-snapshot.v94b1fb2
@clerk/clerk-react 5.2.9-snapshot.v94b1fb2
@clerk/remix 4.2.4-snapshot.v94b1fb2
@clerk/clerk-sdk-node 5.0.17-snapshot.v94b1fb2
@clerk/shared 2.4.0-snapshot.v94b1fb2
@clerk/tanstack-start 0.1.8-snapshot.v94b1fb2
@clerk/testing 1.2.0-snapshot.v94b1fb2
@clerk/themes 2.1.13-snapshot.v94b1fb2
@clerk/types 4.9.0-snapshot.v94b1fb2

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

npm i @clerk/astro@1.0.1-snapshot.v94b1fb2 --save-exact

@clerk/backend

npm i @clerk/backend@1.4.0-snapshot.v94b1fb2 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.1.5-snapshot.v94b1fb2 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.10.0-snapshot.v94b1fb2 --save-exact

@clerk/elements

npm i @clerk/elements@0.10.5-snapshot.v94b1fb2 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.2.8-snapshot.v94b1fb2 --save-exact

@clerk/express

npm i @clerk/express@0.0.18-snapshot.v94b1fb2 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.20-snapshot.v94b1fb2 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.5.0-snapshot.v94b1fb2 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.2.5-snapshot.v94b1fb2 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.2.9-snapshot.v94b1fb2 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.4-snapshot.v94b1fb2 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.17-snapshot.v94b1fb2 --save-exact

@clerk/shared

npm i @clerk/shared@2.4.0-snapshot.v94b1fb2 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.1.8-snapshot.v94b1fb2 --save-exact

@clerk/testing

npm i @clerk/testing@1.2.0-snapshot.v94b1fb2 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.13-snapshot.v94b1fb2 --save-exact

@clerk/types

npm i @clerk/types@4.9.0-snapshot.v94b1fb2 --save-exact

@anagstef
anagstef force-pushed the stefanos/eco-51-gettoken-null-in-production branch from 94b1fb2 to d7dc9e1 Compare July 22, 2024 12:01
@anagstef
anagstef marked this pull request as ready for review July 22, 2024 17:50

@brkalow brkalow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👏

@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

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

Package Version
@clerk/astro 1.0.2-snapshot.vcbde650
@clerk/backend 1.4.1-snapshot.vcbde650
@clerk/chrome-extension 1.1.6-snapshot.vcbde650
@clerk/clerk-js 5.10.1-snapshot.vcbde650
@clerk/clerk-expo 1.2.9-snapshot.vcbde650
@clerk/express 0.0.19-snapshot.vcbde650
@clerk/fastify 1.0.21-snapshot.vcbde650
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.5.1-snapshot.vcbde650
@clerk/nextjs 5.2.6-snapshot.vcbde650
@clerk/remix 4.2.5-snapshot.vcbde650
@clerk/clerk-sdk-node 5.0.18-snapshot.vcbde650
@clerk/tanstack-start 0.1.9-snapshot.vcbde650
@clerk/testing 1.2.1-snapshot.vcbde650

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

npm i @clerk/astro@1.0.2-snapshot.vcbde650 --save-exact

@clerk/backend

npm i @clerk/backend@1.4.1-snapshot.vcbde650 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.1.6-snapshot.vcbde650 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.10.1-snapshot.vcbde650 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.2.9-snapshot.vcbde650 --save-exact

@clerk/express

npm i @clerk/express@0.0.19-snapshot.vcbde650 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.21-snapshot.vcbde650 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.5.1-snapshot.vcbde650 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.2.6-snapshot.vcbde650 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.5-snapshot.vcbde650 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.18-snapshot.vcbde650 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.1.9-snapshot.vcbde650 --save-exact

@clerk/testing

npm i @clerk/testing@1.2.1-snapshot.vcbde650 --save-exact

@nikosdouvlis nikosdouvlis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes sense to me 👍🏻

@anagstef
anagstef merged commit d465d70 into main Jul 23, 2024
@anagstef
anagstef deleted the stefanos/eco-51-gettoken-null-in-production branch July 23, 2024 21:23
brkalow pushed a commit that referenced this pull request Jul 24, 2024
…shake payload (#3764)

This PR fixes an issue on Remix where getToken() returns no token when redirecting back when sign-in and handshake are triggered.

The issue exists because the getToken() is getting the session token from the request cookie, but when returning from an external sign-in page (e.g. OAuth or Account Portal) on the request there is still the __clerk_handshake cookie, because it's not yet resolved. The issue exists only on production, and also does not happen to nextjs, because middleware has already resolved the handshake.

With this PR we pass the session token that exists inside the handshake payload to be returned when calling getToken().
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