Myat Zuckerberg
Myat Zuckerberg

Reputation: 85

Laravel Firebase Mobile Number (OTP) authentication

Is there any best way to integrate Firebase mobile number (otp) authentication to Laravel ? or any package ?

Upvotes: 4

Views: 7769

Answers (2)

董承樺
董承樺

Reputation: 326

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();
}

Upvotes: 5

Akshay
Akshay

Reputation: 209

https://www.codeproject.com/Articles/1256245/Integrate-Firebase-Phone-Authentication-With-Larav

This is something you can see.

As of now I don't found any package in laravel to do so. you have to do it manually.

Upvotes: -1

Related Questions