User pools for Amazon Cognito - CredentialsError: Missing credentials in the config

I am trying to create web application authentication using this tutorial. Here is the code I wrote -

var app = {}; app.configureCognito = function(){ AWSCognito.config.region = 'us-east-1'; var poolData = { UserPoolId: 'userPoolId', ClientId: 'ClientId' }; var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData); var userData = { UserName:'MyName', Pool: userPool }; var attributeList = []; var dataEmail = { Name: 'email', Value: ' mailme@mydomain.com ' }; var dataPhoneNumber = { Name: 'phone_number', Value: '+9112212212212' }; var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail); var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber); attributeList.push(attributeEmail); attributeList.push(attributePhoneNumber); var cognitoUser; userPool.signUp('userName','password',attributeList,null,function(err,result){ if(err){ console.log(err); alert(err); return; } cognitoUser = result.user; console.log('User Name is: '+cognitoUser); }); }; 

I get the "Missing credentials in config" error message, I understand that here we are not performing any AWSCognito.config.credentials assignment, but is it not intended to use the information provided in the userPool object? Is there something wrong with the code for any missing part or something else? According to UserPoolId and client ID, both are 100% correct. Any help would be appreciated.

+6
source share
1 answer

I decided that using the code below, obviously, there is no need to provide IdentityPoolId in this example at all, it's just placeholders that can be left below:

 AWS.config.region = 'us-east-1'; // Region AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: '...' }); AWSCognito.config.region = 'us-east-1'; AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: '...' }); 

Both the credentials AWS.config.credentials and AWSCognito.config.credentials must be set. After completing the above steps, AWSCognito.config needs to be updated as shown below:

 // Need to provide placeholder keys unless unauthorised user access is enabled for user pool AWSCognito.config.update({accessKeyId: 'anything', secretAccessKey: 'anything'}) var poolData = { UserPoolId : 'user pool id collected from user pool', ClientId : 'application client id of app subscribed to user pool' }; 

dataPhoneNumber and userData are optional, dataPhoneNumber should be provided if necessary to check sms for registration.

The problem was solved after the above was in place, Identity-Code is a working model if someone wants to take a look at it.

+9
source

All Articles