redirect(); } public function callback(string $provider) { try { $oauthUser = get_socialite_provider($provider)->user(); $user = User::whereEmail($oauthUser->email)->first(); if (! $user) { $settings = instanceSettings(); // Allow OAuth registration if either general registration OR OAuth-specific registration is enabled if (! $settings->is_registration_enabled && ! $settings->oauth_registration_enabled) { abort(403, 'Registration is disabled'); } $user = User::create([ 'name' => $oauthUser->name, 'email' => $oauthUser->email, 'oauth_only' => $settings->oauth_only, ]); } Auth::login($user); return redirect('/'); } catch (\Exception $e) { $errorCode = $e instanceof HttpException ? 'auth.failed' : 'auth.failed.callback'; return redirect()->route('login')->withErrors([__($errorCode)]); } } }