From 3cd268bcfcc9e69029cfb5c61a2c4bc9ff72d81a Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sat, 18 Nov 2023 09:02:39 +0100 Subject: [PATCH] fix: do not prompt for connections in-game --- .eslintrc | 1 + apps/client/src/lib/utils.ts | 4 ++++ .../lib/validation/does-user-have-required-connections.ts | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index cf7fd82e3..06e6fcdfd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,6 +22,7 @@ } }, "rules": { + "capitalized-comments": "off", "@typescript-eslint/no-non-null-asserted-optional-chain": "error", "@typescript-eslint/no-unnecessary-type-constraint": "error", "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error", diff --git a/apps/client/src/lib/utils.ts b/apps/client/src/lib/utils.ts index be12bbbb4..7cf4589f7 100644 --- a/apps/client/src/lib/utils.ts +++ b/apps/client/src/lib/utils.ts @@ -113,6 +113,10 @@ export function formatOfficerDepartment(unit: Officer | EmsFdDeputy) { return getUnitDepartment(unit)?.value.value ?? null; } +/** + * Check if a user can use third party connections. It will check if the user is inside of an iframe. + * @returns {boolean} + */ export function canUseThirdPartyConnections() { if (typeof window === "undefined") return true; return window.location === window.parent.location; diff --git a/apps/client/src/lib/validation/does-user-have-required-connections.ts b/apps/client/src/lib/validation/does-user-have-required-connections.ts index 50265fec0..7778fba68 100644 --- a/apps/client/src/lib/validation/does-user-have-required-connections.ts +++ b/apps/client/src/lib/validation/does-user-have-required-connections.ts @@ -1,5 +1,6 @@ import { Feature, Rank, type User } from "@snailycad/types"; import { DEFAULT_DISABLED_FEATURES } from "hooks/useFeatureEnabled"; +import { canUseThirdPartyConnections } from "lib/utils"; interface VerifyUserConnectionsOptions { user: User; @@ -11,8 +12,13 @@ export function doesUserHaveAllRequiredConnections(options: VerifyUserConnection const discordId = options.user.discordId; const isOwner = options.user.rank === Rank.OWNER; + // Owner does not require to have all connections if (isOwner) { - // owner does not require to have all connections + return true; + } + + // We cannot ask the user to connect to a third party if they're inside of an iframe. + if (!canUseThirdPartyConnections()) { return true; }