Firebase Auth 在部署到 Heroku 后不起作用.仍然在本地主机:4200 的开发中工作



将我的 Angular 7 应用程序部署到 heroku 后,我对 Google 和 Facebook 的 Firebase 身份验证不再有效。两者都显示相同的错误消息(如下(。即使在隐身模式下,它们也会显示相同的错误消息(与下面的错误消息相同(。

我已经将 Firebase 授权网域中的 myDomain.com 和 myDomain.herokuapp.com 列入白名单。我还向我的谷歌开发控制台的授权域添加了 myDomain.herokuapp.com。

glogin() {
this.socialLogin(new auth.GoogleAuthProvider());
}
fbLogin() {
this.socialLogin(new auth.FacebookAuthProvider());
}
socialLogin(provider) {
this.afAuth.auth.signInWithRedirect(provider)
.then((user) => {
console.log('Sign in with google: ', user);
}).catch(() => {
// Todo - something went wrong
});
}

我得到的错误是:

Uncaught (in promise): Error: Cannot match any routes. URL Segment: '__/auth/handler'
Error: Cannot match any routes. URL Segment: '__/auth/handler'

Uncaught (in promise): Error: Cannot match any routes. URL Segment: '__/auth/iframe'
Error: Cannot match any routes. URL Segment: '__/auth/iframe'

Uncaught Error: Network Error
at main.115259c96fcb9456163d.js:1
at o (main.115259c96fcb9456163d.js:1)
at e.invokeTask (polyfills.ef2a861f18352d657dcf.js:1)
at t.runTask (polyfills.ef2a861f18352d657dcf.js:1)
at t.invokeTask (polyfills.ef2a861f18352d657dcf.js:1)
at invoke (polyfills.ef2a861f18352d657dcf.js:1)
at n.args.<computed> (polyfills.ef2a861f18352d657dcf.js:1)

如果您在实施上述方法后仍然像我一样挣扎,只需转到 Firebase 控制台,然后在"登录方法"下的"授权域"选项卡上,添加您的 Heroku 应用域。

通过进入我的生产环境和我的 Firebase 配置来修复它,将身份验证域从 myDomain.com 更改为 myFirebaseProjectId.firebaseapp.com,它奏效了!

最新更新