我想要实现的目标
问题
问题
更改电子邮件表单
saveNewEmailAddress(email: string) {
this.authService.updateEmailAddress(email);
}
验证服务
电子邮件似乎出现在intelliSense中(所以我希望它有效:))。但是,如何通过密码?
updateEmailAddress(email: string) {
const currentUser = firebase.auth().currentUser;
const credentials = firebase.auth.EmailAuthProvider.credential(currentUser.email, password);
currentUser.reauthenticateWithCredential(credentials).then(function () {
currentUser.updateEmail(email).then(function () {
// Success
}).catch(function (error) {
// An error happened.
});
})
}
这里有任何帮助,代码示例,建议将不胜感激。对此非常陌生。
更新
这就是我的工作方式。请告知这是否合适。我改变的是:
帐户组件HTML
<!-- Password -->
<div class="form-group" [ngClass]="{'has-error': (customerForm.get('password').touched || customerForm.get('password').dirty) && !customerForm.get('password').valid }">
<label class="col-md-2 control-label" for="passwordId">Password</label>
<input #currentPassword class="form-control" id="passwordId" type="text" placeholder="Password(required)" formControlName="password"/>
<span class="help-block" *ngIf="(customerForm.get('password').touched || customerForm.get('password').dirty) && customerForm.get('password').errors">
<span *ngIf="customerForm.get('password').errors.required">
Please enter your Password.
</span>
<span *ngIf="customerForm.get('password').errors.minlength"> The password must be longer than 10 characters. </span>
</span>
</div>
<!-- Save Button -->
<div class="form-group">
<button class="btn btn-primary" type="submit" [disabled]="!customerForm.valid" (click)="saveNewEmailAddress(newEmail.value, currentPassword.value);"> Save </button>
</div>
帐户组件TS
saveNewEmailAddress(email: string, password: string) {
this.authService.updateEmailAddress(email, password);
}
验证服务
updateEmailAddress(email: string, password: string) {
const currentUser = firebase.auth().currentUser;
const credentials = firebase.auth.EmailAuthProvider.credential(currentUser.email, password);
currentUser.reauthenticateWithCredential(credentials).then(function () {
currentUser.updateEmail(email).then(function () {
console.log('i think it worked!');
currentUser.sendEmailVerification().then(function () {
console.log('email sent');
}).catch(function (error) {
// An error happened.
});
}).catch(function (error) {
console.log(error);
});
})
}
答案 0 :(得分:0)
我设法通过在电子邮件更改弹出窗口中包含密码确认来解决此问题。这样我就可以将密码值传入服务,因此重新认证:)