kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

AuthError: syntax error #104

Closed pietersonbadoa closed 2 years ago

pietersonbadoa commented 2 years ago

I got the following Error while trying to fetch user info by firebase uid:

Kreait\Firebase\Exception\Auth\AuthError: syntax error, unexpected '|', expecting variable (T_VARIABLE) in file /var/www/lemontree/vendor/kreait/firebase-php/src/Firebase/Exception/AuthApiExceptionConverter.php on line 54

#0 /var/www/lemontree/vendor/kreait/firebase-php/src/Firebase/Auth/ApiClient.php(218): Kreait\Firebase\Exception\AuthApiExceptionConverter->convertException()
#1 /var/www/lemontree/vendor/kreait/firebase-php/src/Firebase/Auth/ApiClient.php(137): Kreait\Firebase\Auth\ApiClient->requestApi()
#2 /var/www/lemontree/vendor/kreait/firebase-php/src/Firebase/Auth.php(107): Kreait\Firebase\Auth\ApiClient->getAccountInfo()
#3 /var/www/lemontree/vendor/kreait/firebase-php/src/Firebase/Auth.php(88): Kreait\Firebase\Auth->getUsers()
#4 /var/www/lemontree/app/Http/Controllers/Api/v1/Auth/AuthController.php(38): Kreait\Firebase\Auth->getUser()

This is my laravel controller method:

    public function fetch_firebase_user_by_uid(Request $r)
    {

        $auth = app('firebase.auth');
        $uid = trim($r->uid);
        $firebaseUser = $auth->getUser($uid);
        //$token = $this->createuser_from_firebasedata($firebaseUser);
        //return response(['data' => $token]);

    }

PHP verson: 8.0.3 Laravel version: 8.12

jeromegamez commented 2 years ago

Please also share the installed versions of kreait/laravel-firebase and kreait/firebase-php (with composer show).

Your code looks fine, but none of the occurrences mentioned in the stack trace contain a | character, at least not in Release 5.22 of the SDK.

The info that this is a Syntax error leads me to believe that the environment this code is running in might in fact not be PHP 8 (or even PHP 7.4).

Can you confirm the PHP version when you insert a dd(phpversion()); or dd(PHP_VERSION); in the controller?

pietersonbadoa commented 2 years ago

You are right, apparently my apache is running php7.4.16 instead of php8.0 (which is what printed out when I typed php --version on terminal). I tried to switch back and forward between those two php version on my apache, but the error persists.

I'm thinking maybe I messed up something somewhere on my Firebase project configuration, but have no idea how to debug that out.

I'll try to reproduce this problem on a fresh Laravel installation. And let you know the result..

Thanks for speedy reply btw.. :)

pietersonbadoa commented 2 years ago

Okay I'm closing this issue because apparently this is just a silly mistake from a newbie.. I tested on a fresh laravel installation on my apache server, the problem exist.. But when I tried to run the laravel artisan serve instead, and the code works fine... So the problem is on my apache/php installation instead of the library.

jeromegamez commented 2 years ago

Thanks for sharing your findings!