phplaravellaravel-socialite

Undefined method 'stateless'. With Google in Laravel Socialite


I have a controller that I am using for Google auth in my Livewire app. I am able to make a call to google and get the user, I however have an intelephense(P1013) error. After looking around I disabled PHP Intelephense and the error went away as pointed out here. Asking people to do the same when checking my code does not seem to make any sense. Is there a way I can fix this and have Intelephense enabled? my class snippet is

class GoogleAuthController extends Controller
{
    public function redirectToGoogle()
    {
        return Socialite::driver('google')->redirect();
    }


    public function handleGoogleCallback()
    {
        $googleUser = Socialite::driver('google')->stateless()->user();
        dd($googleUser);
    }
}

Solution

  • You can use a docblock to remove the red curly underlines under the stateless() function.

    /** @var \Laravel\Socialite\Two\GoogleProvider  */
    $driver = Socialite::driver('google');
    
    return $driver->stateless()->user();