scopes(['name', 'email']) ->redirect(); } public function handleProviderCallback(string $driver) { $social = Socialite::driver($driver)->user(); $user = User::where(['email' => strtolower($social->getEmail())])->first(); if ($user == null) { $user = User::where(['username' => strtolower($social->getNickname())])->first(); } if ($user) { Auth::login($user); $updates = []; if ($user->profile_photo_path == null) { $updates['profile_photo_path'] = $social->getAvatar(); } if ($user->email == null) { $updates['email'] = $social->getEmail(); } $updates = array_purge($updates); if (! empty($updates)) { $user->update($updates); } return redirect()->route('dashboard'); } else { $provider = ucfirst($driver); return redirect() ->route('login') ->withErrors("Email {$social->getEmail()} not found for {$provider} login."); } } }