Skip to content

Commit

Permalink
fix: no openid scope crash
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRivers committed Mar 2, 2024
1 parent a15b184 commit bc78dab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/__tests__/sdk/utilities/token-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ describe('token-utils', () => {
);
expect(await sessionManager.getSessionItem('id_token')).toBe(mockIdToken);
});

it('stores all provided tokens to memory no id_token', async () => {
const { token: mockAccessToken } = mocks.getMockAccessToken({domain});

Check failure on line 37 in lib/__tests__/sdk/utilities/token-utils.spec.ts

View workflow job for this annotation

GitHub Actions / main (18.x)

Argument of type '{ domain: string; }' is not assignable to parameter of type 'string'.
const tokenCollection: TokenCollection = {
refresh_token: 'refresh_token',
access_token: mockAccessToken,
};
await commitTokensToMemory(sessionManager, tokenCollection);

expect(await sessionManager.getSessionItem('refresh_token')).toBe(
tokenCollection.refresh_token
);
expect(await sessionManager.getSessionItem('access_token')).toBe(
mockAccessToken
);
expect(await sessionManager.getSessionItem('id_token')).toBe(null);
});
});

describe('commitTokenToMemory()', () => {
Expand Down
4 changes: 4 additions & 0 deletions lib/sdk/utilities/token-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const commitTokenToMemory = async (
token: string,
type: TokenType
): Promise<void> => {
if (!token) {
await sessionManager.removeSessionItem(type);
return;
}
if (type !== 'refresh_token' && isTokenExpired(token)) {
throw new KindeSDKError(
KindeSDKErrorCode.INVALID_TOKEN_MEMORY_COMMIT,
Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/utilities/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface TokenCollection {
refresh_token: string;
access_token: string;
id_token: string;
id_token?: string;
}

export interface UserType {
Expand Down

0 comments on commit bc78dab

Please sign in to comment.