Mat*_*ino 5 error-handling firebase-authentication angular
我正在尝试使用 Angular 和 Firebase 身份验证构建一个应用程序。
auth.service.ts
async loginWithEmailAndPassword(email: string, password: string) {
try {
await this.auth.signInWithEmailAndPassword(email, password);
} catch(error) {
throw error;
}
}
Run Code Online (Sandbox Code Playgroud)
登录页面.组件
async loginWithEmailAndPassword() {
if (this.form.status !== 'INVALID') {
try {
await this.authService.loginWithEmailAndPassword(this.email?.value, this.password?.value)
} catch(error) {
console.log('Hello, this is my custom error');
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?我认为尝试...捕捉可以防止这种情况发生。
我什至尝试删除 async wait 语法,但没有任何改变。
小智 0
我使用以下代码来捕获组件中的错误
登录页面.组件
this.auth.SignIn(this.email, this.password).then(function(result){
console.log(result);
}).catch(function(e){
console.log(e);
});
Run Code Online (Sandbox Code Playgroud)
认证服务
return this.afAuth.auth.signInWithEmailAndPassword(email, password);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
401 次 |
| 最近记录: |