AWS cognito registration and login - how to store pool and app id

leighly9 :

I'm using this example to setup a registration/login UI with an AWS Cognito user pool: https://medium.com/@gmonne/custom-authentication-using-aws-cognito-e0b489badc3f

The author suggests keeping the user pool and application IDs private by creating a config.js file that saves this information in two global variables. From the readme.md:

Before running this code you should create a JavaScript file inside the javascript folder called config.js. Here you should set your "User Pool" id and app client id on the window object using the names: USER_POOL_ID, and CLIENT_ID.

I set the variables in config.js as follows, but get a USER_POOL_ID is not defined error.

var USER_POOL_ID: "us-east-1_#######";
var APP_CLIENT_ID: "7pcmh9gre807########";

From the cognito.js file in the example:

(function(win, CognitoUserPool) {

var CognitoUserPool = window.AmazonCognitoIdentity.CognitoUserPool,
AWSCognito = window.AWSCognito,
CognitoIdentityServiceProvider = AWSCognito.CognitoIdentityServiceProvider,CognitoUserAttribute = CognitoIdentityServiceProvider.CognitoUserAttribute,
CognitoUser = CognitoIdentityServiceProvider.CognitoUser,
AuthenticationDetails = CognitoIdentityServiceProvider.AuthenticationDetails,
UserPool = new CognitoUserPool({
UserPoolId : window.USER_POOL_ID, // Your user pool id here
ClientId : window.CLIENT_ID, // Your client id here

What is the syntax to set the IDs on the window object as mentioned in the readme?

Dan :

Variables are set using = not :, so change config.js:

var USER_POOL_ID = "us-east-1_#######";
var APP_CLIENT_ID = "7pcmh9gre807########";

It's not clear how this file is being used but if you wanted to set the window object directly, you would do

window.USER_POOL_ID = "us-east-1_#######";
window.APP_CLIENT_ID = "7pcmh9gre807########";

And the cognito.js code isn't using the correct variable name, it has no APP_ prefix, so change the last line to:

ClientId : window.APP_CLIENT_ID, // Your client id here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=28265&siteId=1