当前位置: 首页 > 知识库问答 >
问题:

未捕获错误:调用未定义的方法Kreait

董子平
2023-03-14

我刚刚创建了php web服务器并将其连接到firebase。当我尝试身份验证时,注册工作正常。但问题在于登录。它不断出现以下错误:

致命错误:未捕获错误:调用未定义的方法Kreait\Firebase\Auth::在 /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php:24Stack跟踪:#0{main}抛出 /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php第24行

<?php
include("includes/db.php");


if(isset($_POST['signup']))
{

    $email = $_POST['emailSignup'];
    $pass = $_POST['passSignup'];

    $auth = $firebase->getAuth();
    $user = $auth->createUserWithEmailAndPassword($email,$pass);
    header("Location:index.php");
}

else
{

    $email = $_POST['emailSignin'];
    $pass = $_POST['passSignin'];

    $auth = $firebase->getAuth();
    $user = $auth->getUserWithEmailAndPassword($email,$pass);
    if($user)
    {
        session_start();
        $_SESSION['user'] = true;
        header("Location:home.php");
    }


}

?>

这是我的数据库连接代码:


<?php

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Auth;

// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyCHULFKW6Kl7FXZc3ZUTYL8fq0f90-kAJ0';

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount, $apiKey)
    // The following line is optional if the project id in your credentials file
    // is identical to the subdomain of your Firebase project. If you need it,
    // make sure to replace the URL with the URL of your project.
    ->withDatabaseUri('https://phpserver-f35e3.firebaseio.com/')
    ->create();

$database = $firebase->getDatabase();


?>

暂时还没有答案

 类似资料: