user(); // Users who must set a password first (magic link invitees) stay on the password page // (CheckForcePasswordReset); they need a known password to confirm the 2FA setup. if (! $user || filled($user->two_factor_confirmed_at) || $user->force_password_reset) { return $next($request); } $teamId = data_get(session('currentTeam'), 'id'); if (is_null($teamId) || in_array($request->path(), allowedPathsForTwoFactorSetup(), true)) { return $next($request); } // Read the flag from the database: the session and cache can hold a team from before the change. if (! Team::query()->whereKey($teamId)->value('is_two_factor_required')) { return $next($request); } if ($request->expectsJson() || $request->routeIs('*livewire.update')) { abort(403, 'Your team requires two-factor authentication. Configure it to continue.'); } return redirect()->route('two-factor.required'); } }