diff --git a/__tests__/Auth0Client/logout.test.ts b/__tests__/Auth0Client/logout.test.ts index 8d3016642..4103cd417 100644 --- a/__tests__/Auth0Client/logout.test.ts +++ b/__tests__/Auth0Client/logout.test.ts @@ -132,7 +132,7 @@ describe('Auth0Client', () => { ); }); - it('clears the cache', async () => { + it('clears the cache for the global clientId', async () => { const auth0 = setup(); jest @@ -141,7 +141,39 @@ describe('Auth0Client', () => { await auth0.logout(); + expect(auth0['cacheManager']['clear']).toHaveBeenCalledWith( + TEST_CLIENT_ID + ); + }); + + it('clears the cache for the provided clientId', async () => { + const auth0 = setup(); + + jest + .spyOn(auth0['cacheManager'], 'clear') + .mockReturnValueOnce(Promise.resolve()); + + await auth0.logout({ clientId: 'client_123' }); + + expect(auth0['cacheManager']['clear']).toHaveBeenCalledWith('client_123'); + expect(auth0['cacheManager']['clear']).not.toHaveBeenCalledWith( + TEST_CLIENT_ID + ); + }); + + it('clears the cache for all client ids', async () => { + const auth0 = setup(); + + jest + .spyOn(auth0['cacheManager'], 'clear') + .mockReturnValueOnce(Promise.resolve()); + + await auth0.logout({ clientId: null }); + expect(auth0['cacheManager']['clear']).toHaveBeenCalled(); + expect(auth0['cacheManager']['clear']).not.toHaveBeenCalledWith( + TEST_CLIENT_ID + ); }); it('removes authenticated cookie from storage when `options.onRedirect` is set', async () => { diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 41d21ea35..ff6cd3402 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -828,7 +828,11 @@ export class Auth0Client { public async logout(options: LogoutOptions = {}): Promise { const { openUrl, ...logoutOptions } = patchOpenUrlWithOnRedirect(options); - await this.cacheManager.clear(); + if (options.clientId === null) { + await this.cacheManager.clear(); + } else { + await this.cacheManager.clear(options.clientId || this.options.clientId); + } this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain diff --git a/src/global.ts b/src/global.ts index b48a39ca3..1ec7ca321 100644 --- a/src/global.ts +++ b/src/global.ts @@ -410,7 +410,7 @@ export interface LogoutUrlOptions { * * [Read more about how redirecting after logout works](https://auth0.com/docs/logout/guides/redirect-users-after-logout) */ - clientId?: string; + clientId?: string | null; /** * Parameters to pass to the logout endpoint. This can be known parameters defined by Auth0 or custom parameters