I've developed an mobile App with react native where I am using firebase as backend. Now I am developing a website with wordpress for that app and I need to use the firebase database (firestore) and authentification in my website.
So I have a registration form on my website and I am using an action hook to get the data, the user entered in. Now I want to use that data and authenticate the user with firebase auth.
I used the firebase functions in Javascript for now in my app but for that case I need PHP.
I think Firebase-Admin-SDK for PHP is the correct choose. https://firebase-php.readthedocs.io/en/latest/
Unfortunately I don't really know how to use that.
I created a wordpress plugin with composer dependencies and uploaded it via FTP to my wordpress site. The plugin is also activated.
With the following code I try to create a dummy user in firebase.
Unfortunately there isn't any new record in my firebase. I don't know why it doesn't work and I am pretty new to PHP and wordpress so I don't know how to solve this problem. I know that the hook is getting called.
<?php
/**
* Plugin Name: Own Functions
* Plugin URI:
* Description: PHP code
* Author: xxx
* Version: 2.1.91
* Text Domain: insert-php
* Domain Path: /languages/
* Author URI:
*/
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
$auth = $firebase->getAuth();
add_action('swpm_front_end_registration_complete_user_data', 'registration_callback_firebase');
function registration_callback_firebase ($member_info)
{
$userProperties = [
'email' => 'user@example.com',
'emailVerified' => false,
'phoneNumber' => '+15555550100',
'password' => 'secretPassword',
'displayName' => 'John Doe',
'photoUrl' => 'http://www.example.com/12345678/photo.png',
'disabled' => false,
];
$createdUser = $auth->createUser($userProperties);
// This is equivalent to:
$request = \Kreait\Auth\Request\CreateUser::new()
->withUnverifiedEmail('user@example.com')
->withPhoneNumber('+15555550100')
->withClearTextPassword('secretPassword')
->withDisplayName('John Doe')
->withPhotoUrl('http://www.example.com/12345678/photo.png');
$createdUser = $auth->createUser($request);
}
Is this the correct attempt? Or is it possible to call a javascript function (and pass the entered data) in this PHP action hook and do everything with javascript?
I would appreciate any tips if that's the right way or how I can achieve my goals.