Having trouble getting Cognito’s Forgot password feature to work
Using: Angular2+Typescript+Ionic
New to this process, followed a Quickstart guide I found here
No matter what I try, keep getting errors like Cannot read property 'CognitoUser' of undefined
import { Component } from '@angular/core';
import { NavController, LoadingController } from 'ionic-angular';
import { TabsPage } from '../tabs/tabs';
import { SignupPage } from '../signup/signup';
import { ConfirmPage } from '../confirm/confirm';
import { LoginPage } from '../login/login';
import {Camera, CameraOptions} from '@ionic-native/camera';
import { Cognito } from '../../providers/aws.cognito';
import { User } from '../../providers/providers';
import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@ionic-native/Media-Capture';
import {
AuthenticationDetails,
CognitoIdentityServiceProvider,
CognitoUser,
CognitoUserAttribute,
CognitoUserPool
} from "aws-cognito-identity";
declare var AWS: any;
declare const aws_cognito_identity_pool_id;
declare const aws_cognito_region;
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
var CognitoUser = AmazonCognitoIdentity.CognitoUser;
recovery()
{
AWS.config.region = aws_cognito_region;
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
var userData = {
Username : ‘testuser’,
Pool : aws_cognito_identity_pool_id
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
// call forgotPassword on cognitoUser
cognitoUser.forgotPassword({
onSuccess: function(result) {
console.log('call result: ' + result);
},
onFailure: function(err) {
alert(err);
},
inputVerificationCode() {
var verificationCode = prompt('Please input verification code ', '');
var newPassword = prompt('Enter new password ', '');
cognitoUser.confirmPassword(verificationCode, newPassword, this);
}
});
alert("It should have worked");
}