diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 177c1a969..0fc1aa0b2 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -1073,18 +1073,13 @@ describe('Auth0', () => { expect(token).toBe(TEST_ACCESS_TOKEN); }); - it('acquires and releases lock when there is a cache', async () => { + it('does not acquire a lock when the cache is available', async () => { const { auth0, cache, lock } = await setup(); cache.get.mockReturnValue({ access_token: TEST_ACCESS_TOKEN }); await auth0.getTokenSilently(); - expect(lock.acquireLockMock).toHaveBeenCalledWith( - GET_TOKEN_SILENTLY_LOCK_KEY, - 5000 - ); - expect(lock.releaseLockMock).toHaveBeenCalledWith( - GET_TOKEN_SILENTLY_LOCK_KEY - ); + + expect(lock.acquireLockMock).not.toHaveBeenCalled(); }); it('continues method execution when there is no cache available', async () => { const { auth0, utils } = await setup(); diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index dc7f51403..9ad33b32a 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -332,8 +332,6 @@ export default class Auth0Client { options.scope = getUniqueScopes(this.DEFAULT_SCOPE, options.scope); try { - await lock.acquireLock(GET_TOKEN_SILENTLY_LOCK_KEY, 5000); - const { audience, scope, @@ -348,11 +346,12 @@ export default class Auth0Client { }); if (cache) { - await lock.releaseLock(GET_TOKEN_SILENTLY_LOCK_KEY); return cache.access_token; } } + await lock.acquireLock(GET_TOKEN_SILENTLY_LOCK_KEY, 5000); + const stateIn = encodeState(createRandomString()); const nonceIn = createRandomString(); const code_verifier = createRandomString();