-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): Fix
getToken()
from getAuth()
return value in v5
- Loading branch information
Showing
3 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
'@clerk/backend': major | ||
--- | ||
|
||
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<string> or throw error). | ||
This change fixes issues with `getToken()` in `@clerk/nextjs` / `@clerk/remix` / `@clerk/fastify` / `@clerk/sdk-node` / `gatsby-plugin-clerk`: | ||
|
||
Example: | ||
```typescript | ||
import { getAuth } from '@clerk/remix'; | ||
|
||
const { getToken } = await getAuth(...); | ||
const jwtString = await getToken(...); | ||
``` | ||
|
||
A breaking change introduced is the change of `clerkClient.sessions.getToken()` return value. To keep the existing behavior use the following: | ||
```typescript | ||
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters