redirect(); } /** * Obtain the user information from Google. */ public function handleGoogleCallback() { try { $googleUser = Socialite::driver('google')->user(); $user = User::firstOrCreate( ['email' => $googleUser->getEmail()], [ 'name' => $googleUser->getName(), 'password' => bcrypt(Str::random(16)), // Generate a random password ] ); Auth::login($user); return redirect()->route('dashboard'); } catch (\Exception $e) { return redirect()->route('login')->withErrors(['error' => 'Unable to login using Google. Please try again.']); } } }