Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions server/middleware/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import type { JwtPayload } from "../types/JwtPayload.js";

const JWT_SECRET = process.env.JWT_SECRET;

function shouldBypassTesterGate(req: Request): boolean {
const host = req.get('host') || req.get('x-forwarded-host') || '';
return host === 'control.pfconnect.online';
}

export async function requireTester(req: Request, res: Response, next: NextFunction) {
try {
if (shouldBypassTesterGate(req)) {
return next();
}

const settings = await getTesterSettings();
if (!settings.tester_gate_enabled) {
return next();
Expand Down Expand Up @@ -48,6 +57,20 @@ export async function isTester(userId: string) {

export async function checkTesterGateStatus() {
try {
const settings = await getTesterSettings();
return settings.tester_gate_enabled || false;
} catch (error) {
console.error('Error checking tester gate status:', error);
return true;
}
}

export async function checkTesterGateStatusWithDomain(host?: string) {
try {
if (host === 'control.pfconnect.online') {
return false;
}

const settings = await getTesterSettings();
return settings.tester_gate_enabled || false;
} catch (error) {
Expand Down
11 changes: 11 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default function App() {
const [showUpdateModal, setShowUpdateModal] = useState(false);
const [activeModal, setActiveModal] = useState<UpdateModal | null>(null);

const shouldBypassTesterGate = () => {
return window.location.hostname === 'control.pfconnect.online';
};

useEffect(() => {
const checkGlobalHolidayStatus = async () => {
try {
Expand Down Expand Up @@ -96,6 +100,12 @@ export default function App() {
useEffect(() => {
const checkGateStatus = async () => {
try {
// Bypass tester gate for control.pfconnect.online
if (shouldBypassTesterGate()) {
setTesterGateEnabled(false);
return;
}

const settings = await getTesterSettings();

if (settings && typeof settings.tester_gate_enabled === 'boolean') {
Expand Down Expand Up @@ -150,6 +160,7 @@ export default function App() {

{activeModal &&
(!testerGateEnabled ||
shouldBypassTesterGate() ||
(testerGateEnabled && user?.isTester) ||
user?.isAdmin) && (
<UpdateOverviewModal
Expand Down
Loading