Firebase PHP API - How to avoid creating a Factory() en every request

Viewed 54

I am using the Kreait Firebase Admin SDK for PHP. According to the docs, in order to validate a TokenID, first I need to create an $auth object running the following code:

$factory = (new Factory)
        ->withServiceAccount('...')
        ->withDatabaseUri('...');

$auth = $factory->createAuth();

However, this needs to be done on every single API Request, it takes about 1s to run it an it's very detremental to the user experience. Is there a way I can avoid to run it on every request or store the $auth object?

1 Answers

The best solution is to stop using PHP and use a serverless backend aproach using firebase functions in Node.

Related