Ash*_*jun 10 android node.js firebase reactjs google-cloud-firestore
我正在使用一个非常简单的代码并从 firestore 获取数据
import firebase from 'firebase/app';
import 'firebase/firestore'
const firebaseApp = firebase.initializeApp({
apiKey: "...",
authDomain: "...",
....
});
const db = firebaseApp.firestore();
export default db;
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误
[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.
Run Code Online (Sandbox Code Playgroud)
现在,我不知道为什么会发生这种情况?
请有人帮助我!
我面临着同样的问题。该连接在某些环境中可以正常工作,但在我客户的公司网络上却不能。
在互联网上进行了长时间的研究后,我在 Github 上发现了一个讨论它的问题。
这对我有用:
const firestoreDB = initializeFirestore(firebaseApp, {
experimentalForceLongPolling: true, // this line
useFetchStreams: false, // and this line
})
Run Code Online (Sandbox Code Playgroud)
这里我使用的是 firebase v9。对于 firebase v8 来说是这样的:
firebase().firestore().settings({
experimentalForceLongPolling: true, // this line
useFetchStreams: false, // and this line
})
Run Code Online (Sandbox Code Playgroud)
确保您的环境指向真正的 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 { }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16839 次 |
最近记录: |