redirect(); } public function callback(string $provider) { try { $oauthUser = get_socialite_provider($provider)->user(); $email = trim((string) $oauthUser->email); if ($email === '') { abort(403, 'OAuth provider did not return an email address'); } $email = strtolower($email); $user = User::whereEmail($email)->first(); if (! $user) { $settings = instanceSettings(); if (! $settings->is_registration_enabled) { abort(403, 'Registration is disabled'); } $user = User::create([ 'name' => $oauthUser->name, 'email' => $email, ]); } Auth::login($user); return redirect('/'); } catch (\Exception $e) { $errorCode = $e instanceof HttpException ? 'auth.failed' : 'auth.failed.callback'; return redirect()->route('login')->withErrors([__($errorCode)]); } } }