Skip to content

Commit ac57ae9

Browse files
authored
preserve current org id when session updates (#27)
1 parent 1f18451 commit ac57ae9

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/session.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ describe('session', () => {
533533
expect(authenticateWithRefreshToken).toHaveBeenCalledWith({
534534
clientId: expect.any(String),
535535
refreshToken: 'refresh.token',
536+
organizationId: 'org-123',
536537
});
537538

538539
// Verify the response contains the new token data

src/session.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ async function updateSession(request: Request, debug: boolean) {
117117
// istanbul ignore next
118118
if (debug) console.log(`Session invalid. Refreshing access token that ends in ${session.accessToken.slice(-10)}`);
119119

120+
const { organizationId } = getClaimsFromAccessToken(session.accessToken);
120121
// If the session is invalid (i.e. the access token has expired) attempt to re-authenticate with the refresh token
121122
const { accessToken, refreshToken } = await getWorkOS().userManagement.authenticateWithRefreshToken({
122123
clientId: getConfig('clientId'),
123124
refreshToken: session.refreshToken,
125+
organizationId,
124126
});
125127

126128
// istanbul ignore next

0 commit comments

Comments
 (0)