【发布时间】:2021-11-15 03:04:58
【问题描述】:
我收到以下错误。我的问题是 NOT 与实际错误,而是说错误是 Uncaught。如果您查看我的 auth.service.ts 和 sign-in.component.ts 文件,我会发现错误。
我的问题是,为什么在控制台中出现 Error: Uncaught (in promise) 错误?我错过了什么?
我正在使用 "@angular/fire": "^7.0.4" "firebase": "^9.0.2" "rxjs": "6.6.7"
auth.service.ts
/**
* Sign in
*
* @param credentials
*/
signIn(credentials: { email: string; password: string }): Promise<any>
{
return this.auth.signInWithEmailAndPassword(credentials.email, credentials.password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
//console.log(user);
// Store the access token in the local storage
userCredential.user.getIdToken().then(token => {
this.accessToken = token;
//console.log(token);
})
// Set the authenticated flag to true
this._authenticated = true;
// Store the user on the user service
//this._userService.user = user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.log('Show Error', error.code);
throw errorCode;
});
}
登录.component.ts
/**
* Sign in
*/
signIn(): void
{
// Return if the form is invalid
if ( this.signInForm.invalid )
{
return;
}
// Disable the form
this.signInForm.disable();
// Hide the alert
this.showAlert = false;
// Sign in
this._authService.signIn(this.signInForm.value)
.then(
() => {
// Set the redirect url.
// The '/signed-in-redirect' is a dummy url to catch the request and redirect the user
// to the correct page after a successful sign in. This way, that url can be set via
// routing file and we don't have to touch here.
const redirectURL = this._activatedRoute.snapshot.queryParamMap.get('redirectURL') || '/signed-in-redirect';
// Navigate to the redirect url
this._router.navigateByUrl(redirectURL);
},
(response) => {
console.log('error from auth.service', response);
// Re-enable the form
this.signInForm.enable();
// Reset the form
this.signInNgForm.resetForm();
// Set the alert
this.alert = {
type : 'error',
message: 'Wrong email or password'
};
// Show the alert
this.showAlert = true;
}
);
}
【问题讨论】:
-
你再次抛出错误
throw errorCode;,乍一看我没有看到处理该错误的代码。 -
请原谅我的无知,但我该如何解决呢?
-
不重新抛出它是一种选择。另一种是在调用堆栈中捕获更高的重新抛出错误,并在那里处理它而不重新抛出它。
-
我删除了重新抛出并且错误没有返回到
sign-in.component.ts。控制台仍然显示 firebase 错误。 -
你能用代码告诉我如何处理吗?我将不胜感激
标签: javascript angular firebase firebase-authentication angularfire