Is there any best way to integrate Firebase mobile number (otp) authentication to Laravel ? or any package ?
You can make user be authenticated by following firebase official steps to let user verify cellphone number with OTP.
If you want to access firebase from server(Laravel), you can try this package kreait/laravel-firebase and use cellphone number to get whether the user have been authenticated or not.
the code may look like this (you will get user's information if user is authenticated. Otherwise, you will get exception)
use Kreait\Firebase\Factory;
// other code
// change $keyPath to yours, do not just copy and paste
$keyPath = storage_path("app/firebase/blog-361f6-firebase-adminsdk-h5dyf-2287bc06a5.json");
$auth = (new Factory)->withServiceAccount($keyPath)->createAuth();
try {
// change $examplePhoneNumber to yours
$examplePhoneNumber = '+886900000000';
$user = $auth->getUserByPhoneNumber($examplePhoneNumber);
print_r($user);
} catch (Exception $e) {
echo $e->getMessage();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With