@@ -16,16 +16,17 @@ import { AsyncLock } from './async_lock.js';
16
16
* This class is safe to use in concurrent settings, i.e. tests running in parallel.
17
17
*/
18
18
export class AmplifyAuthCredentialsFactory {
19
- private readonly userPoolId : string ;
20
- private readonly userPoolClientId : string ;
21
- private readonly identityPoolId : string ;
22
- private readonly allowGuestAccess : boolean | undefined ;
23
19
/**
24
20
* Asynchronous lock is used to assure that all calls to Amplify JS library are
25
21
* made in single transaction. This is because that library maintains global state,
26
22
* for example auth session.
27
23
*/
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 ;
29
30
30
31
/**
31
32
* Creates Amplify Auth credentials factory.
@@ -47,7 +48,7 @@ export class AmplifyAuthCredentialsFactory {
47
48
iamCredentials : IamCredentials ;
48
49
accessToken : string ;
49
50
} > => {
50
- await this . lock . acquire ( ) ;
51
+ await AmplifyAuthCredentialsFactory . lock . acquire ( ) ;
51
52
try {
52
53
const username = `amplify-backend-${ shortUuid ( ) } @amazon.com` ;
53
54
const temporaryPassword = `Test1@Temp${ shortUuid ( ) } ` ;
@@ -103,12 +104,12 @@ export class AmplifyAuthCredentialsFactory {
103
104
accessToken : authSession . tokens . accessToken . toString ( ) ,
104
105
} ;
105
106
} finally {
106
- this . lock . release ( ) ;
107
+ AmplifyAuthCredentialsFactory . lock . release ( ) ;
107
108
}
108
109
} ;
109
110
110
111
getGuestAccessCredentials = async ( ) : Promise < IamCredentials > => {
111
- await this . lock . acquire ( ) ;
112
+ await AmplifyAuthCredentialsFactory . lock . acquire ( ) ;
112
113
try {
113
114
Amplify . configure ( {
114
115
Auth : {
@@ -131,7 +132,7 @@ export class AmplifyAuthCredentialsFactory {
131
132
132
133
return authSession . credentials ;
133
134
} finally {
134
- this . lock . release ( ) ;
135
+ AmplifyAuthCredentialsFactory . lock . release ( ) ;
135
136
}
136
137
} ;
137
138
}
0 commit comments