4.2.1 Using user pools with AWS JavaScript SDK
Creating an AWSCognitoIdentityUserPool Object
let poolData = {
UserPoolId: "<userPoolId>", // Your user pool id here, you can also use window._config to hold you userPoolId.
ClientId: "<clientId>", // Your client id here, you can also use window._config to hold you clientId.
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);Register a User
//attributeList is the list of parameters which are required for authentication,
//user has already deleared them while creating pool on AWS.
var attributeList = [];
var email = "<email>";
var personalname = "<personalname>";
var dataEmail = {
Name: 'email',
Value: email, //get from form field
};
var dataPersonalName = {
Name: 'name',
Value: personalname, //get from form field
};
var attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);
var attributePersonalName = new AmazonCognitoIdentity.CognitoUserAttribute(dataPersonalName);
attributeList.push(attributeEmail);
attributeList.push(attributePersonalName);
userPool.signUp(username, password, attributeList, null, function (err, result) {
if (err) {
//error while signing up
console.log(err.message);
console.log("result", result);
alert(err.message || JSON.stringify(err));
return;
}
//user successfully signedup
cognitoUser = result.user;
console.log("User Details: ", cognitoUser);
console.log('user name is ' + cognitoUser.getUsername());
});Confirm Signup
Sign in a User
Sign out a user
Previous4.2 Authentication Using AWS Cognito Service WrapperNext4.2.2 Using user pools with Bayun AWSS3 wrapper 'SecureAuthentication'
Last updated