Skip to content

Commit 88658b1

Browse files
authored
Support session migration (#576)
Fixes descope/etc#11907 Passes through the externalToken argument and adds a test for the small override that removes the private argument from descope-js.
1 parent d37df7d commit 88658b1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/index.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ describe('sdk', () => {
251251
});
252252
});
253253

254+
describe('refresh', () => {
255+
it('should call coreSdk.refresh with the correct arguments', async () => {
256+
jest.resetModules();
257+
const refresh = jest.fn();
258+
jest.doMock('@descope/core-js-sdk', () => {
259+
const actual = jest.requireActual('@descope/core-js-sdk');
260+
return {
261+
...actual,
262+
__esModule: true,
263+
wrapWith: (sdkInstance: object) => sdkInstance,
264+
default: (...args: any[]) => ({ ...actual.default(...args), refresh }),
265+
};
266+
});
267+
268+
const createNodeSdk = require('.').default; // eslint-disable-line
269+
const sdkInstance = createNodeSdk({ projectId: 'project-id' });
270+
271+
const token = 'test-token';
272+
const externalToken = 'external-token';
273+
await sdkInstance.refresh(token, externalToken);
274+
275+
expect(refresh).toHaveBeenCalledWith(token, undefined, externalToken);
276+
});
277+
});
278+
254279
describe('validateAndRefreshSession', () => {
255280
it('should throw an error when both session or refresh tokens are empty', async () => {
256281
await expect(sdk.validateAndRefreshSession('', '')).rejects.toThrow(

lib/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ const nodeSdk = ({ authManagementKey, managementKey, publicKey, ...config }: Nod
134134
...coreSdk,
135135

136136
// Overrides core-sdk refresh, because the core-sdk exposes queryParams, which is for internal use only
137-
refresh: async (token?: string) => coreSdk.refresh(token),
137+
refresh: async (token?: string, externalToken?: string) =>
138+
coreSdk.refresh(token, undefined, externalToken),
138139

139140
/**
140141
* Provides various APIs for managing a Descope project programmatically. A management key must
@@ -201,7 +202,9 @@ const nodeSdk = ({ authManagementKey, managementKey, publicKey, ...config }: Nod
201202
},
202203

203204
/**
204-
* Refresh the session using a refresh token
205+
* Refresh the session using a refresh token.
206+
* For session migration, use {@link sdk.refresh}.
207+
*
205208
* @param refreshToken refresh JWT to refresh the session with
206209
* @returns RefreshAuthenticationInfo promise or throws Error if there is an issue with JWTs
207210
*/

0 commit comments

Comments
 (0)