How to use the amazon-cognito-identity-js.CognitoUser function in amazon-cognito-identity-js

To help you get started, we’ve selected a few amazon-cognito-identity-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kangzeroo / Kangzeroos-Complete-AWS-Web-Boilerplate / Boilerplate_Frontend / App / src / api / aws / aws_cognito.js View on Github external
const p = new Promise((res, rej)=>{
		// create the `userData` object for instantiating a new `cognitoUser` object
		const userData = {
			Username: email,
			Pool: userPool
		}
		// create the `cognitoUser` object
		const cognitoUser = new CognitoUser(userData)
		// and call the `resendConfirmationCode()` of `cognitoUser`
		cognitoUser.resendConfirmationCode(function(err, result) {
					// reject promise if confirmation code failed
	        if (err) {
	          console.log(err);
		        rej(err)
						return
	        }
					// resolve if successfull
	        res()
	    })
	})
	return p
github awslabs / aws-cognito-angular-quickstart / src / app / service / user-login.service.ts View on Github external
authenticate(username: string, password: string, callback: CognitoCallback) {
        console.log("UserLoginService: starting the authentication");

        let authenticationData = {
            Username: username,
            Password: password,
        };
        let authenticationDetails = new AuthenticationDetails(authenticationData);

        let userData = {
            Username: username,
            Pool: this.cognitoUtil.getUserPool()
        };

        console.log("UserLoginService: Params set...Authenticating the user");
        let cognitoUser = new CognitoUser(userData);
        console.log("UserLoginService: config is " + AWS.config);
        cognitoUser.authenticateUser(authenticationDetails, {
            newPasswordRequired: (userAttributes, requiredAttributes) => callback.cognitoCallback(`User needs to set password.`, null),
            onSuccess: result => this.onLoginSuccess(callback, result),
            onFailure: err => this.onLoginError(callback, err),
            mfaRequired: (challengeName, challengeParameters) => {
                callback.handleMFAStep(challengeName, challengeParameters, (confirmationCode: string) => {
                    cognitoUser.sendMFACode(confirmationCode, {
                        onSuccess: result => this.onLoginSuccess(callback, result),
                        onFailure: err => this.onLoginError(callback, err)
                    });
                });
            }
        });
    }
github jspsych / jsPsych-Redux-GUI / src / common / backend / cognito / index.js View on Github external
export function forgotPassword(username, onSuccess, onFailure, inputVerificationCode) {
	let cognitoUser = new CognitoUser({
		Username: username,
		Pool: userPool,
	});

	cognitoUser.forgotPassword({
        onSuccess: onSuccess,
        onFailure: onFailure,
        inputVerificationCode: inputVerificationCode
    });
}
github frsechet / cognito-user-pool / src / methods / signupConfirm.js View on Github external
function signupConfirm(poolData, body, cb) {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const { username, confirmationCode } = body;

  const userData = {
    Username: username,
    Pool: userPool,
  };

  const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  cognitoUser.confirmRegistration(confirmationCode, true, (err, res) => cb(err, res));

}
github frsechet / cognito-user-pool / src / profile.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  const refreshToken = new AmazonCognitoIdentity.CognitoRefreshToken({RefreshToken: body.refreshToken});

  const userData = {
    Username : username,
    Pool : userPool
  };

  let cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  return cognitoUser.refreshSession(refreshToken, function(err, userSession) {
    if (err) {
      return cb(err);
    }
    cognitoUser.signInUserSession = userSession;

    return cognitoUser.getUserAttributes(function (err, res) {
      if (err) {
        return cb(err);
      }
      return cb(null, res);
    });

  });
github OffCourse / offcourse-next / packages / app / src / providers / AuthProvider / adapters / Cognito.js View on Github external
confirmNewPassword = async ({ userName, password, confirmationCode }) => {
    const cognitoUser = new CognitoUser({
      Username: userName,
      Pool: this.userPool
    });

    const errorResponses = {};

    return new Promise((resolve, reject) => {
      cognitoUser.confirmPassword(confirmationCode, password, {
        onSuccess: resolve,
        onFailure: error => {
          reject({ general: "invalid confirmation code" });
        }
      });
    });
  };
github jpdillingham / SWoT / web / src / components / security / SecurityActions.js View on Github external
const getCognitoUser = (email) => {
    return new CognitoUser({
        Username: email,
        Pool: getCognitoUserPool(),
    });
};
github tensult / ngx-s3-upload / src / app / auth / service.ts View on Github external
confirmPassword(verficationCode: string, newPassword: string, callback: (error: Error, statusCode: string) => void) {
        if (!this.signupData.username) {
            callback(new Error('Username is Empty.'), AuthService.statusCodes.incompletedSigninData);
            return;
        }
        const authService = this;
        const cognitoUser = new CognitoUser({
            Username: this.signupData.username,
            Pool: this.userPool
        });

        cognitoUser.confirmPassword(verficationCode, newPassword, {
            onSuccess: () => {
                authService.currentStatus = AuthService.statusCodes.passwordChanged;
                callback(null, AuthService.statusCodes.success);
            },
            onFailure: (err: Error) => {
                authService.currentStatus = AuthService.statusCodes.unknownError;
                callback(err, AuthService.statusCodes.unknownError);
            }
        });
    }
github jspsych / jsPsych-Redux-GUI / src / common / backend / cognito / index.js View on Github external
export function forgotPasswordReset(username, verificationCode, newPassword, callback) {
	let cognitoUser = new CognitoUser({
		Username: username,
		Pool: userPool,
	});
	cognitoUser.confirmPassword(verificationCode, newPassword, callback);
}
github elliotforbes / imgur-clone / src / imgur-frontend / src / cognito / cognito.js View on Github external
confirmRegistration (username, code, cb) {
        let cognitoUser = new CognitoUser({
            Username: username,
            Pool: this.userPool
        })
        cognitoUser.confirmRegistration(code, true, cb)
    }