user(); if ($user === null || $user->hasTwoFactorEnabled()) { return $next($request); } $value = $this->settings->get(Setting::TwoFactorEnforcement); $enforcement = (is_string($value) ? TwoFactorEnforcement::tryFrom($value) : null) ?? TwoFactorEnforcement::None; if (! $enforcement->appliesTo($user->type)) { return $next($request); } // password.confirm is on this list because the two-factor mutation // routes now require it: without the exemption, enrolling would // redirect to the confirm-password screen, which this middleware // would redirect straight back to two-factor.show — a loop that // locks the user out of the only exit. if ($request->routeIs('two-factor.*', 'password.confirm', 'logout', 'locale.update')) { return $next($request); } return WriteSafeRedirect::apply($request, redirect()->route('two-factor.show')->with('two_factor_enforced_notice', true)); } }