wordpress - How Do I Turn My Firebase Firestore Project From Test Mode Into Production Mode using PHP?

How do we authenticate the app to the Firestore? (not using service account), because when service account have conflicts when security rules which needs authenticate. When I'm switching to production mode and perform a query I got this message

enter image description here

This is the rules that is set in the production mode

match /{document=**} {
   allow read, write: if request.auth!=null;
}

match /projects/{document=**} {
   allow read, write;
}

Answer

Solution:

If you are using https://github.com/kreait/firebase-php/, the documentation shows how to initialize Firebase Authentication, and then sign-in with one of the many supported providers.

Once you're signed in, the authentication information is securely passed with your requests to the database and you can then access it as request.auth in your security rules as shown here.

Answer

Solution:

You need to authenticate your PHP app first to the Firebase in order your App to make a request.

To do that, follow this quick solution which I recently discovered.

  1. First You must create your own authentication email and password in your Firebase Authenticate Console.

  2. Install this package on your App:

composer require kreait/firebase-php

  1. Once you are done installing the package, you may proceed here.
use Kreait\Firebase\Factory;
use Kreait\Firebase\Auth;
use Kreait\Firebase\Auth\SignInResult;

$key = ""
$factory = (new Factory)
->withServiceAccount($key)
->withDatabaseUri('Your Firebase Database URi');
$auth = $factory->createAuth();

$email = "Your Email";
$password = "Your Password";
$signInResult = $auth->signInWithEmailAndPassword($email, $password);

note: Remember, this is only static and you have to make the entire function to make this more dynamic.

Now you can make a request to the firebase without getting block by the security rules.

Reference:

Source