Laravel Socialite Google login failed and returns empty dd()

Viewed 13

I am trying to use Socialite in Laravel to login with Google accounts and Facebook accounts

I installed Socilaite package and added 'google' driver to services.php and made all the necessary configurations in the database and the providers and I made the facebook login and it works well, but google is not working well

The functions

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

public function handleGoogleCallback()
{
    try {
 
        $user = Socialite::driver('google')->user();
  
        $finduser = User::where('social_id', $user->id)->first();
  
        if($finduser){
            Auth::login($finduser);
 
            return redirect(route('home'));
        } else {
            $newUser = User::create([
                'name' => $user->name,
                'email' => $user->email,
                'social_id'=> $user->id,
                'social_type'=> 'google',
                'password' => encrypt('my-google')
            ]);
 
            Auth::login($newUser);
  
            return redirect(route('home'));
        }
 
    } catch (Exception $e) {
        dd($e->getMessage());
    }
}

And this is what I get

Output

0 Answers
Related