使用模拟器时,Firestore 规则中的 request.auth 为 null

Inc*_*Cat 6 emulation firebase angular google-cloud-firestore

我正在通过AngularFire和测试 Firestore 规则Firebase Emulators
我的firestore rule很简单,只检查用户是否登录。
问题是,尽管用户已经过身份验证,但不允许任何用户访问Firestore

但是当我不使用模拟器(即使用真正的 Firestore )时,这是允许的。

所以我想知道我使用Emulator时是否需要进行额外的设置?请帮我!

浏览器控制台:

core.js:6210 ERROR Error: Uncaught (in promise): FirebaseError: [code=permission-denied]: PERMISSION_DENIED: 
false for 'create' @ L5
Run Code Online (Sandbox Code Playgroud)

我的环境:

  • firebase-工具:9.8.0
  • 角度:11.2.12
  • @角度/火:6.1.4

我的 Firestore 规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序模块.ts:

core.js:6210 ERROR Error: Uncaught (in promise): FirebaseError: [code=permission-denied]: PERMISSION_DENIED: 
false for 'create' @ L5
Run Code Online (Sandbox Code Playgroud)

应用程序组件.html:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序组件.ts:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFireAuthModule,
    AngularFirestoreModule,
  ],
  providers: [
    { provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9099] : undefined },
    { provide: USE_DATABASE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9000] : undefined },
    { provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 8080] : undefined },

  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

Inc*_*Cat 5

毕竟,我尝试升级firebase-tools,它的版本变成了9.8到9.10,然后我的问题就解决了。我发现了这个问题,它似乎是 Firebase 模拟器的问题。谢谢。