@@ -18,8 +18,6 @@ License for the specific language governing permissions and limitations under th
1818 * Exports Loader as the plugin constructor
1919 * and Store as store that can be used with Vuex.Store()
2020 */
21- import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers' ;
22- import { CognitoIdentityClient , GetIdCommand , GetCredentialsForIdentityCommand } from '@aws-sdk/client-cognito-identity' ;
2321import { LexRuntimeServiceClient } from '@aws-sdk/client-lex-runtime-service' ;
2422import { LexRuntimeV2Client } from '@aws-sdk/client-lex-runtime-v2' ;
2523import { PollyClient } from '@aws-sdk/client-polly' ;
@@ -161,7 +159,8 @@ export class Loader {
161159 const mergedConfig = mergeConfig ( defaultConfig , config ) ;
162160 let credentials ;
163161 if ( mergedConfig . cognito . poolId != '' || localStorage . getItem ( 'poolId' ) ) {
164- credentials = this . getCredentials ( mergedConfig ) . then ( ( creds ) => {
162+ credentials = this . store . dispatch ( 'getCredentials' , mergeConfig ) . then ( ( creds ) => {
163+ //credentials = this.getCredentials(mergedConfig).then((creds) => {
165164 return creds ;
166165 } ) ;
167166 }
@@ -185,56 +184,6 @@ export class Loader {
185184 } ) ;
186185 this . app = app ;
187186 }
188-
189- async getCredentials ( context ) {
190- const region = context . region || context . cognito . poolId . split ( ':' ) [ 0 ] || 'us-east-1' ;
191- const poolId = context . cognito . poolId || localStorage . getItem ( 'poolId' ) ;
192- const appUserPoolName = context . cognito . appUserPoolName || localStorage . getItem ( 'appUserPoolName' ) ;
193- const poolName = `cognito-idp.${ region } .amazonaws.com/${ appUserPoolName } ` ;
194- const appUserPoolClientId = context . cognito . appUserPoolClientId || localStorage . getItem ( 'appUserPoolClientId' )
195- const idtoken = localStorage . getItem ( `${ appUserPoolClientId } idtokenjwt` ) ;
196- let logins ;
197- if ( idtoken ) {
198- logins = { } ;
199- logins [ poolName ] = idtoken ;
200- const client = new CognitoIdentityClient ( { region } ) ;
201- const getIdentityId = new GetIdCommand ( {
202- IdentityPoolId : poolId ,
203- Logins : logins ? logins : { }
204- } )
205- let identityId , getCreds ;
206-
207- try {
208- await client . send ( getIdentityId )
209- . then ( ( res ) => {
210- identityId = res . IdentityId ;
211- getCreds = new GetCredentialsForIdentityCommand ( {
212- IdentityId : identityId ,
213- Logins : logins ? logins : { }
214- } )
215- } )
216- const res = await client . send ( getCreds ) ;
217- const creds = res . Credentials ;
218- const credentials = {
219- accessKeyId : creds . AccessKeyId ,
220- identityId,
221- secretAccessKey : creds . SecretKey ,
222- sessionToken : creds . SessionToken ,
223- expiration : creds . Expiration ,
224- } ;
225- return credentials ;
226- } catch ( err ) {
227- console . log ( err )
228- }
229- } else {
230- const credentialProvider = fromCognitoIdentityPool ( {
231- identityPoolId : poolId ,
232- clientConfig : { region } ,
233- } )
234- const credentials = credentialProvider ( )
235- return credentials
236- }
237- }
238187}
239188
240189// comment out for prod build
0 commit comments