Reputation: 453
I am using Laravel and I have a small firestore app, it works well but I also want to authenticate
users in firestore after they have authenticated at my site, how can I achieve this?
I am connecting to firestore via a FirestoreClient:
use Google\Cloud\Firestore\FirestoreClient;
$this->firestore = new FirestoreClient([
'projectId' => config('chat.firebase_project_id')
]);
and then, i'm creating a user like this:
public function createUser($token, $fullName, $avatar)
{
$this->firestore->collection(self::CHAT_USERS_COLLECTION)->document($token)->create([
'_id' => $token,
'username' => $fullName,
'avatar' => $avatar
]);
}
This works well and I can do basic CRUD
operations on my collections, however my users are not authenticated
, how can I achieve this?
Upvotes: 0
Views: 312
Reputation: 599021
Since your PHP code runs on the server, there is no way to sign in to Firebase Authentication with an SDK there. Even if you were to pass the user's ID tokens from the client to your PHP code on the server, there is no way to then make authenticated calls to Firestore on behalf of those users. Calls from this SDK run with elevated privileges, and can't impersonate a Firebase Authentication user.
If you want the calls to be handled by Firestore as coming from the user who is signed in to Firebase Authentication, the calls must be made from the place where the user is signed in (so from your front-end site).
Upvotes: 1