Skip to content

fix(backend): Fix getToken() from getAuth() return value in v5 - #2539

Merged
dimkl merged 1 commit into
mainfrom
sdk-1192-get-token
Jan 11, 2024
Merged

fix(backend): Fix getToken() from getAuth() return value in v5#2539
dimkl merged 1 commit into
mainfrom
sdk-1192-get-token

Conversation

@dimkl

@dimkldimkl commented Jan 10, 2024

Copy link
Copy Markdown
Contributor

Description

Change SessionApi.getToken() to return consistent { data, errors } return value and fix the getToken() from requestState to have the same return behavior as v4 (return Promise or throw error).
This change fixes issues with getToken() in @clerk/nextjs / @clerk/remix / @clerk/fastify / @clerk/sdk-node / gatsby-plugin-clerk:

Example:

import{getAuth}from'@clerk/nextjs/server';const{ getToken }=awaitgetAuth(...);constjwtString=awaitgetToken(...);

The change in SessionApi.getToken() return value is a breaking change, to keep the existing behavior use the following:

import{ClerkAPIResponseError}from'@clerk/shared/error';constresponse=awaitclerkClient.sessions.getToken(...);if(response.errors){const{ status, statusText, clerkTraceId }=response;consterror=newClerkAPIResponseError(statusText||'',{data: [],status: Number(status||''),
clerkTraceId,});error.errors=response.errors;throwerror;}// the value of the v4 `clerkClient.sessions.getToken(...)`constjwtString=response.data.jwt;

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:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

@dimkldimkl added bug Something isn't working v5-release labels Jan 10, 2024
@dimkldimkl self-assigned this Jan 10, 2024
@changeset-bot

changeset-botBot commented Jan 10, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 37fac81

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

This PR includes changesets to release 7 packages
NameType
@clerk/backendMajor
@clerk/fastifyPatch
gatsby-plugin-clerkPatch
@clerk/nextjsPatch
@clerk/remixPatch
@clerk/clerk-sdk-nodePatch
@clerk/elementsPatch

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

@dimkl
dimklforce-pushed the sdk-1192-get-token branch from fa82747 to e2d6e6bCompareJanuary 10, 2024 15:40
@dimkl
dimklforce-pushed the sdk-1192-get-token branch 2 times, most recently from 404043b to 60ba984CompareJanuary 10, 2024 16:33
@dimkl

Copy link
Copy Markdown
ContributorAuthor

!snapshot

@dimkl

Copy link
Copy Markdown
ContributorAuthor

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

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

PackageVersion
@clerk/backend1.0.1-snapshot.v60ba984
@clerk/chrome-extension1.0.1-snapshot.v60ba984
@clerk/clerk-js5.0.1-snapshot.v60ba984
@clerk/elements0.0.3-snapshot.v60ba984
@clerk/clerk-expo1.0.1-snapshot.v60ba984
@clerk/fastify1.0.1-snapshot.v60ba984
gatsby-plugin-clerk5.0.1-snapshot.v60ba984
@clerk/localizations2.0.1-snapshot.v60ba984
@clerk/nextjs5.0.1-snapshot.v60ba984
@clerk/clerk-react5.0.1-snapshot.v60ba984
@clerk/remix4.0.1-snapshot.v60ba984
@clerk/clerk-sdk-node5.0.1-snapshot.v60ba984
@clerk/shared2.0.1-snapshot.v60ba984
@clerk/themes2.0.1-snapshot.v60ba984
@clerk/types4.0.1-snapshot.v60ba984

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

npm i @clerk/backend@1.0.1-snapshot.v60ba984 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.0.1-snapshot.v60ba984 --save-exact

@clerk/elements

npm i @clerk/elements@0.0.3-snapshot.v60ba984 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.0.1-snapshot.v60ba984 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.1-snapshot.v60ba984 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.1-snapshot.v60ba984 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.0.1-snapshot.v60ba984 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.0.1-snapshot.v60ba984 --save-exact

@clerk/remix

npm i @clerk/remix@4.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.1-snapshot.v60ba984 --save-exact

@clerk/shared

npm i @clerk/shared@2.0.1-snapshot.v60ba984 --save-exact

@clerk/themes

npm i @clerk/themes@2.0.1-snapshot.v60ba984 --save-exact

@clerk/types

npm i @clerk/types@4.0.1-snapshot.v60ba984 --save-exact

@dimkl
dimklforce-pushed the sdk-1192-get-token branch 2 times, most recently from 2f08925 to 7ffbc66CompareJanuary 10, 2024 18:41
@dimkl
dimklforce-pushed the sdk-1192-get-token branch from 7ffbc66 to 37fac81CompareJanuary 11, 2024 09:35
@SokratisVidros

Copy link
Copy Markdown
Contributor

We will proceed with this change in V6.

@dimkl
dimkl added this pull request to the merge queue Jan 11, 2024
Merged via the queue into main with commit 799abc2Jan 11, 2024
@dimkl
dimkl deleted the sdk-1192-get-token branch January 11, 2024 14:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backendbugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dimkl@clerk-cookie@SokratisVidros@nikosdouvlis