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

ignezio's avatar

Laravel\Socialite\Two\InvalidStateException Error

Hello, everyone as of recent larval has been showing this error to me this is a recent error with no changes in code or environment im pretty lost on why this is happening and any help is greatly appreciated. my controller is below. I Believe that the error is accusing at the second try catch block but I don't know what could be causing the error I've also tried using stateless but that doesn't seem to work either.

controller.


        try {
            $user = Socialite::driver('google')->user();
        } catch (\Exception $e) {
            return redirect($e);
        }
        $existingUser = User::where('email', $user->email)->first();
        if($existingUser){
            // log them in
            auth()->login($existingUser, true);
            return redirect('/');
        } else {
        try {
            $user = Socialite::driver('google')->user();
            $create                  = new User;
            $create->name            = $user->name;
            $create->email           = $user->email;
            $create->google_id       = $user->id;
            $create->avatar          = $user->avatar;
            $create->avatar_original = $user->avatar_original;
            $create->save();
            Auth::loginUsingId($create->id);

            return redirect('/');

        } catch (Exception $e) {

            return $e;

        }
    }

error.

Laravel\Socialite\Two\InvalidStateException in /var/www/vendor/laravel/socialite/src/Two/AbstractProvider.php:209 Stack trace: #
0 likes
0 replies

Please or to participate in this conversation.