1
votes

I have some firebase projects.
Auth project for sign. And firestore project for storing.

Rules for firestore project is

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

Previously, I used firebase admin sdk via firebase functions to get whole controls of firestore project.

Is it possible to use auth for firestore on client when rules are like below

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

Briefly, I've implemented...

if (!this.auth && !_auth) {
      this.authApp = firebase.initializeApp(Env.FirebaseAuthConfig, 'auth')
      this.auth = this.authApp.auth()
    }

    if (!this.firestore && !_firestore) {
      this.firestoreApp = firebase.initializeApp(Env.FirebaseFirestoreConfig, 'firestore')
      this.firestoreApp.auth(this.authApp)
      this.firestore = this.firestoreApp.firestore()
    }

But FirebaseError: Missing or insufficient permissions occurred on request

Please give me some advices

1

1 Answers

0
votes

Why not use Auth and Firestore in the same project? If you setup Auth in the same project as your firestore then yes, you can use the if request.auth != null; security rule.

Also, the beginning of this video explains how auth works so it can be used by clients.