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 calledconfig.js
. Here you should set your "User Pool" id and app client id on the window object using the names:USER_POOL_ID
, andCLIENT_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?
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