Skip to content

Commit

Permalink
Merge branch 'master' into silent-login-params
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hobbs authored Jan 24, 2020
2 parents 3e5e459 + b925472 commit 3ad921f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
11 changes: 3 additions & 8 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down

0 comments on commit 3ad921f

Please sign in to comment.