无效标记- firebase

dsekswqp  于 2023-02-09  发布在  其他
关注(0)|答案(2)|浏览(120)

我想在Vercel上部署Web应用程序时遇到了一个问题。我正在开发一个具有登录功能的应用程序。在本地环境中,一切正常,登录/注销功能工作正常,但当我部署到Vercel时,显示错误

The token is invalid: file_put_contents(/var/task/user/storage/framework/cache/data/24/fc/24fc69d48eaa682f929a7045e8f4700237c0083e): failed to open stream: No such file or directory

我还添加了网络应用程序到授权域。
下面是我验证令牌的代码:

try {
                $signInResult = $auth->signInWithEmailAndPassword($request->email, $request->password);
                $idTokenString = $signInResult->idToken();

                try {
                    /** @var \Lcobucci\JWT\Token\Plain $verifiedIdToken */
                    $verifiedIdToken = $auth->verifyIdToken($idTokenString);

                    $uid = $verifiedIdToken->claims()->get('sub');

                    $_SESSION['displayName'] = $signInResult->data()["displayName"];
                    $_SESSION['verified_user_id'] = $uid;
                    $_SESSION['idTokenString'] = $idTokenString;

                    $_SESSION['status'] = "Logged in successfully";

                    return redirect()->route('userHome');
                } catch (InvalidToken $e) {
                    echo 'The token is invalid: ' . $e->getMessage();
                } catch (\InvalidArgumentException $e) {
                    echo 'The token could not be parsed: ' . $e->getMessage();
                }
wooyq4lh

wooyq4lh1#

当资源尝试保存或读取的文件夹不存在时,通常会发生此类错误。请确保在将凭据保存到该位置之前创建该位置的文件夹路径结构,如果该文件夹不存在,则应在应用中将其作为文件流处理,这是一个潜在的故障点。

n3ipq98p

n3ipq98p2#

尝试创建会话cookie给定从客户端应用程序发送到服务器应用程序的ID令牌,您可以将其转换为会话cookie:

use Kreait\Firebase\Auth\CreateSessionCookie\FailedToCreateSessionCookie;

$idToken = '...';

// The TTL must be between 5 minutes and 2 weeks and can be provided as
// an integer value in seconds or a DateInterval

$fiveMinutes = 300;
$oneWeek = new \DateInterval('P7D');

try {
    $sessionCookieString = $auth->createSessionCookie($idToken, $oneWeek);
} catch (FailedToCreateSessionCookie $e) {
    echo $e->getMessage();
}

使用COOKIES维护您的用户授权流程

验证Firebase会话Cookie

Use Auth::verifySessionCookie() to verify a Session Cookie:

use Kreait\Firebase\Exception\Auth\FailedToVerifySessionCookie;

$sessionCookieString = '...';

try {
    $verifiedSessionCookie = $auth->verifySessionCookie($sessionCookieString);
} catch (FailedToVerifySessionCookie $e) {
    echo 'The Session Cookie is invalid: '.$e->getMessage();
}

$uid = $verifiedSessionCookie->claims()->get('sub');

$user = $auth->getUser($uid);

相关问题