Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sam-O's avatar
Level 1

How to get rid of error that does not exist?!

Hello everyone, i'm using Socialite with laravel, all up to date and i wrote this code:

public function GoogleCallback()
    {
        //Validate provided token
        $validator = Validator::make(request()->all(), [
            'access_token' => 'required|string'
        ]);

        //Return bad request if validation failed
        if ($validator->fails()) {
            return response([
                'status' => 'failed',
                'error' => $validator->errors()
            ], 400);
        }

        $providerUser = Socialite::driver('google')->userFromToken(request()->access_token);
        try {
        } catch (Exception $exception) {
            return response([
                'status' => 'failed',
                'error' => 'Invalid credentials provided.'
            ], 401);
        }

        $user = User::updateOrCreate(
            [
                'email' => $providerUser->getEmail(),
            ],
            [
                'name' => $providerUser->getName(),
                'google_id' => $providerUser->getId(),
            ]
        );

        $user->email_verified_at = $user->email_verified_at ?? now();
        $user->save();

        $token = UserController::CreateToken($user);

        //Return Ok with user's data
        return response([
            'status' => 'success',
            'message' => 'User logged in successfully.',
            'data' => [
                'name' => $user->name,
                'user_name' => $user->user_name,
                'email' => $user->email,
                'store_id' =>  $user->store->id ?? null,
                'token' => $token
            ]
        ], 200);
    }

I did not write anything in my app.config related to Socialite. The function works greate with postman with no error, but VScode tell me there is an error with userFromToken and this the error message:

Undefined method 'userFromToken'.intelephense(P1013)
function AbstractProvider::userFromToken(string $token): User
Get a Social User instance from a known access token.

Loading...

No quick fixes available

and i cant see the function userFromToken, like its not existing. I tried to search for any solution i did not found. any idea ?

PS: not only userFromToken also stateless function and other functions with the same problem.

0 likes
5 replies
Snapey's avatar

try vscode command Index Workspace

1 like
Sam-O's avatar
Level 1

An update, the indexing did not solve the problem :(

tykus's avatar
tykus
Best Answer
Level 104

This is an Intelephense "error" because the return type from driver is theProvider contract, not the GoogleProvider specifically. You solve this "error" by hinting:

/** @var \Laravel\Socialite\Two\GoogleProvider $providerUser */
$providerUser = Socialite::driver('google');
$providerUser->userFromToken(request()->access_token);

Or, probably by installing and configuring IdeHelper package.

1 like
Sam-O's avatar
Level 1

@tykus installing the IdeHelper package resolve the problem, thanks.

Please or to participate in this conversation.