【问题标题】:FirebaseError: Firebase: A network AuthError (such as timeout, interrupted connection or unreachable host) has occurred. (auth/network-request-failed)FirebaseError:Firebase:发生网络AuthError(例如超时、连接中断或主机无法访问)。 (身份验证/网络请求失败)
【发布时间】:2021-11-02 20:26:09
【问题描述】:

我想将我的 Angular 应用设置为使用 Firebase 的模拟器,并按照this guide 设置我的app.module.ts,如下所示:

import { USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/compat/auth';
import { USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/compat/database';
import { USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/compat/firestore';

@NgModule({
  // ... Existing configuration
  providers: [
    // ... Existing Providers
    { provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['http://localhost', 9099] : undefined },
    { provide: USE_DATABASE_EMULATOR, useValue: environment.useEmulators ? ['http://localhost', 9000] : undefined },
    { provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['http://localhost', 8080] : undefined },
  ]
})
export class AppModule { }

运行firebase emulators:startng serve 后没有错误。如果我尝试登录,我会在 Chrome 中收到以下错误:FirebaseError: Firebase: A network AuthError (such as timeout, interrupted connection or unreachable host) has occurred. (auth/network-request-failed)。还有一个网络请求失败:POST http://localhost/identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY net::ERR_CONNECTION_REFUSED

如果我在 FireFox 中尝试相同的操作,我会收到以下错误:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY. (Reason: CORS request did not succeed) 以及我在 Chrome 中遇到的错误。

我所遵循的指南说使用 localhost 而不是 http://localhost 虽然当页面加载时,我在 DevTools 控制台中收到错误 FirebaseError: Firebase: Emulator URL must start with a valid scheme (http:// or https://). (auth/invalid-emulator-scheme)。我正在使用"@angular/fire": "^7.0.3"

我可以做些什么来解决这个问题?

【问题讨论】:

  • 看来您已经克服了标题中提到的错误,现在出现了 CORS 错误。我建议更新标题和问题以反映这一点。
  • @BizzyBob 感谢您的建议!我已更新问题以反映新问题。
  • 您可以使用--disable-web-security 标志运行Chrome,如here 所述。这是我在mac上一直使用的open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security

标签: javascript angular firebase-authentication firebase-tools


【解决方案1】:

我设法通过降级到@angular/fire v6 来解决这个问题

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 2021-08-28
    • 2018-01-26
    • 2020-04-13
    • 2017-02-24
    • 2021-01-03
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多