login(username: string, password: string): Observable<{ type: string, result: any }>{
const authData = {
Username: username,
Password: password
};
const authDetails = new AuthenticationDetails(authData);
const userData = {
Username: username,
Pool: userPool
};
this.cognitoUser = new CognitoUser(userData);
return new Observable<{ type: string, result: any}>(obs => {
this.cognitoUser.authenticateUser(authDetails, {
onSuccess: (result: any) => {
obs.next({ type: 'success', result: result });
obs.complete();
},
onFailure: (error: any) => obs.error(error),
newPasswordRequired: (userAttributes, requiredAttributes) => {
obs.next({ type: 'newPasswordRequired', result: [userAttributes, requiredAttributes] });
obs.complete();
}
});
});
}