@@ -16,16 +16,17 @@ import { AsyncLock } from './async_lock.js';
1616 * This class is safe to use in concurrent settings, i.e. tests running in parallel.
1717 */
1818export class AmplifyAuthCredentialsFactory {
19- private readonly userPoolId : string ;
20- private readonly userPoolClientId : string ;
21- private readonly identityPoolId : string ;
22- private readonly allowGuestAccess : boolean | undefined ;
2319 /**
2420 * Asynchronous lock is used to assure that all calls to Amplify JS library are
2521 * made in single transaction. This is because that library maintains global state,
2622 * for example auth session.
2723 */
28- private readonly lock : AsyncLock = new AsyncLock ( 60 * 1000 ) ;
24+ private static readonly lock : AsyncLock = new AsyncLock ( 60 * 1000 ) ;
25+
26+ private readonly userPoolId : string ;
27+ private readonly userPoolClientId : string ;
28+ private readonly identityPoolId : string ;
29+ private readonly allowGuestAccess : boolean | undefined ;
2930
3031 /**
3132 * Creates Amplify Auth credentials factory.
@@ -47,7 +48,7 @@ export class AmplifyAuthCredentialsFactory {
4748 iamCredentials : IamCredentials ;
4849 accessToken : string ;
4950 } > => {
50- await this . lock . acquire ( ) ;
51+ await AmplifyAuthCredentialsFactory . lock . acquire ( ) ;
5152 try {
5253 const username = `amplify-backend-${ shortUuid ( ) } @amazon.com` ;
5354 const temporaryPassword = `Test1@Temp${ shortUuid ( ) } ` ;
@@ -103,12 +104,12 @@ export class AmplifyAuthCredentialsFactory {
103104 accessToken : authSession . tokens . accessToken . toString ( ) ,
104105 } ;
105106 } finally {
106- this . lock . release ( ) ;
107+ AmplifyAuthCredentialsFactory . lock . release ( ) ;
107108 }
108109 } ;
109110
110111 getGuestAccessCredentials = async ( ) : Promise < IamCredentials > => {
111- await this . lock . acquire ( ) ;
112+ await AmplifyAuthCredentialsFactory . lock . acquire ( ) ;
112113 try {
113114 Amplify . configure ( {
114115 Auth : {
@@ -131,7 +132,7 @@ export class AmplifyAuthCredentialsFactory {
131132
132133 return authSession . credentials ;
133134 } finally {
134- this . lock . release ( ) ;
135+ AmplifyAuthCredentialsFactory . lock . release ( ) ;
135136 }
136137 } ;
137138}
0 commit comments