我正在从AWS控制台创建一个Cognito用户。要求我在首次登录时更改密码。我想提示一个新页面或在登录页面中隐藏一个div以允许用户传递新密码。您能帮我如何使用以下代码提示新密码页面吗?
login.tml
<div class="login">
<div>
<form class="login-form"
[formGroup]="loginForm"
(ngSubmit)="onLogin()" >
<div >
<div fxFlexFill>
<mat-form-field >
<input
type="email"
matInput
placeholder="Your email"
formControlName="email">
<mat-error>Invalid or missing email.</mat-error>
</mat-form-field>
</div>
</div>
<div >
<div >
<mat-form-field >
<input
type="password"
matInput
placeholder="password"
formControlName="password">
<mat-error>Missing password.</mat-error>
</mat-form-field>
</div>
</div>
Login.ts
export class Login implements OnInit {
constructor(private example:ExampleService,
private _router: Router) {
}
onLogin() {
const email=this.loginForm.get('email').value
const password=this.loginForm.get('password').value
this.example.LogIn(email, password).subscribe((data) => {
this._router.navigate(['/home']);
}, (err)=> {
});
}
ExampleService.ts
LogIn(email, password) {
return Observable.create(observ => {
cognitoUser.authenticateUser(authenticationDetails, {
newPasswordRequired: function(userAttributes, requiredAttributes) {
//How do I prompt a new password page from here and collect the form
value
and pass the value on below password paramaters
const email1={
email:email
};
cognitoUser.completeNewPasswordChallenge(password, email1, this)
},
onSuccess: function (result) {
observ.next(result);
observ.complete();
},
onFailure: function(err) {
console.log(err);
observ.error(err);
},
});
});
}
不知道如何验证用户是否是首次使用。如果这是第一次使用,该如何在回调函数(newPasswordRequired:function())中显示新页面。