+ /**
+ * Get the failed login response instance.
+ *
+ * @param \Illuminate\Http\Request $request
+ *
+ * @throws \Illuminate\Validation\ValidationException
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ protected function sendFailedLoginResponse(Request $request)
+ {
+ throw ValidationException::withMessages([
+ $this->username() => [trans('auth.failed')],
+ ])->redirectTo('/login');
+ }
+
+ /**
+ * Update the intended URL location from their previous URL.
+ * Ignores if not from the current app instance or if from certain
+ * login or authentication routes.
+ */
+ protected function updateIntendedFromPrevious(): void
+ {
+ // Store the previous location for redirect after login
+ $previous = url()->previous('');
+ $isPreviousFromInstance = (strpos($previous, url('/')) === 0);
+ if (!$previous || !setting('app-public') || !$isPreviousFromInstance) {
+ return;
+ }
+
+ $ignorePrefixList = [
+ '/login',
+ '/mfa',
+ ];
+
+ foreach ($ignorePrefixList as $ignorePrefix) {
+ if (strpos($previous, url($ignorePrefix)) === 0) {
+ return;
+ }
+ }
+
+ redirect()->setIntendedUrl($previous);
+ }
+
+ /**
+ * Check if login auto-initiate should be valid based upon authentication config.
+ */
+ protected function shouldAutoInitiate(): bool
+ {
+ $socialDrivers = $this->socialAuthService->getActiveDrivers();
+ $authMethod = config('auth.method');
+ $autoRedirect = config('auth.auto_initiate');
+
+ return $autoRedirect && count($socialDrivers) === 0 && in_array($authMethod, ['oidc', 'saml2']);
+ }
+
+ /**
+ * Logout user and perform subsequent redirect.
+ *
+ * @param \Illuminate\Http\Request $request
+ *
+ * @return mixed
+ */
+ public function logout(Request $request)
+ {
+ $this->traitLogout($request);
+
+ $redirectUri = $this->shouldAutoInitiate() ? '/login?prevent_auto_init=true' : '/';
+
+ return redirect($redirectUri);
+ }