redirect(); } /** * Callback from OAuth provider. */ protected function callback(Request $request, string $driver): RedirectResponse { $oauthUser = Socialite::driver($driver)->user(); // User is already logged in and wants to link a new OAuth Provider if ($request->user()) { $oauth = $request->user()->oauth; $oauth[$driver] = $oauthUser->getId(); $this->updateService->handle($request->user(), ['oauth' => json_encode($oauth)]); return redirect()->route('account'); } try { $user = User::query()->whereJsonContains('oauth->'. $driver, $oauthUser->getId())->firstOrFail(); $this->auth->guard()->login($user, true); } catch (Exception $e) { // No user found - redirect to normal login return redirect()->route('auth.login'); } return redirect('/'); } }