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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

dimkl
Copy link
Member

@dimkl dimkl commented Jan 10, 2024

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 } = await getAuth(...);
const jwtString = await getToken(...);

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';

const response = await clerkClient.sessions.getToken(...);

if (response.errors) {
    const { status, statusText, clerkTraceId } = response;
    const error = new ClerkAPIResponseError(statusText || '', {
        data: [],
        status: Number(status || ''),
        clerkTraceId,
    });
    error.errors = response.errors;

    throw error;
}

// the value of the v4 `clerkClient.sessions.getToken(...)`
const jwtString = 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

@dimkl dimkl added bug Something isn't working v5-release labels Jan 10, 2024
@dimkl dimkl self-assigned this Jan 10, 2024
Copy link

changeset-bot bot commented Jan 10, 2024

馃 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
Name Type
@clerk/backend Major
@clerk/fastify Patch
gatsby-plugin-clerk Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/elements 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

@dimkl
Copy link
Member Author

dimkl commented Jan 10, 2024

!snapshot

@dimkl
Copy link
Member Author

dimkl commented Jan 10, 2024

!snapshot

@clerk-cookie
Copy link
Collaborator

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

Package Version
@clerk/backend 1.0.1-snapshot.v60ba984
@clerk/chrome-extension 1.0.1-snapshot.v60ba984
@clerk/clerk-js 5.0.1-snapshot.v60ba984
@clerk/elements 0.0.3-snapshot.v60ba984
@clerk/clerk-expo 1.0.1-snapshot.v60ba984
@clerk/fastify 1.0.1-snapshot.v60ba984
gatsby-plugin-clerk 5.0.1-snapshot.v60ba984
@clerk/localizations 2.0.1-snapshot.v60ba984
@clerk/nextjs 5.0.1-snapshot.v60ba984
@clerk/clerk-react 5.0.1-snapshot.v60ba984
@clerk/remix 4.0.1-snapshot.v60ba984
@clerk/clerk-sdk-node 5.0.1-snapshot.v60ba984
@clerk/shared 2.0.1-snapshot.v60ba984
@clerk/themes 2.0.1-snapshot.v60ba984
@clerk/types 4.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 dimkl force-pushed the sdk-1192-get-token branch 2 times, most recently from 2f08925 to 7ffbc66 Compare January 10, 2024 18:41
@SokratisVidros
Copy link
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 799abc2 Jan 11, 2024
7 checks passed
@dimkl dimkl deleted the sdk-1192-get-token branch January 11, 2024 14:31
dimkl added a commit to clerk/clerk-docs that referenced this pull request Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend bug Something isn't working v5-release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants