无法访问 Cloud Firestore 后端。连接失败 1 次

IT技术 android node.js reactjs firebase google-cloud-firestore
2021-05-03 20:31:48

我正在使用一个非常简单的代码并从 Firestore 中获取数据

import firebase from 'firebase/app';
import 'firebase/firestore'

const firebaseApp = firebase.initializeApp({
        apiKey: "...",
        authDomain: "...",
        ....
    });
    
const db = firebaseApp.firestore();
    
export default db;

但我一直收到这个错误

[2021-06-05T00:58:41.274Z]  @firebase/firestore: Firestore (8.6.5): Could not reach Cloud Firestore backend. Connection failed 1 times.
Most recent error: FirebaseError: [code=permission-denied]:
 Permission denied on resource project.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

  1. 我确实有一个非常快的互联网连接
  2. 我的时钟也与标准时间同步

现在,我不知道为什么会这样?

请有人帮帮我!!!

2个回答

我能够通过直接使用我的凭据来解决这个问题,我 initializeApp 我的 firebase 配置,我以前从我的 env 文件中调用它们,我认为我的应用程序之前没有获得 env

确保您的环境指向真正的 firestone 数据库,而不是 Firestore 模拟器。当我遇到同样的问题时,这就是原因。

我使用的是 Angular 框架,所以我不得不在 app.module.ts 文件中注释掉这些环境引用。

@NgModule({
  declarations: [AppComponent, InformUserComponent],
  entryComponents: [InformUserComponent],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AppRoutingModule,
    ServiceWorkerModule.register('ngsw-worker.js', {
      enabled: environment.production,
      // Register the ServiceWorker as soon as the app is stable
      // or after 30 seconds (whichever comes first).
      registrationStrategy: 'registerWhenStable:30000'
    }),

  ],
  providers: [AuthService, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    // {
    //   provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ?
    //     ['localhost', 8080] : undefined
    // },
    // {
    //   provide: USE_FUNCTIONS_EMULATOR, useValue: environment.useEmulators ?
    //     ['localhost', 5001] : undefined
    // },
  ],
  bootstrap: [AppComponent],
})
export class AppModule { }

在此处输入图片说明