diff --git a/packages/api/src/controllers/auth/User.ts b/packages/api/src/controllers/auth/User.ts index ea11099c9..7e71f1550 100644 --- a/packages/api/src/controllers/auth/User.ts +++ b/packages/api/src/controllers/auth/User.ts @@ -16,7 +16,6 @@ import { ExtendedBadRequest } from "src/exceptions/ExtendedBadRequest"; import { Socket } from "services/SocketService"; import { handleStartEndOfficerLog } from "lib/leo/handleStartEndOfficerLog"; import { ShouldDoType } from "@prisma/client"; -import { isDiscordIdInUse } from "utils/discord"; @Controller("/user") @UseBefore(IsAuth) @@ -35,7 +34,7 @@ export class AccountController { @Patch("/") @Description("Update the authenticated user's settings") async patchAuthUser(@BodyParams() body: any, @Context("user") user: User) { - const { username, discordId, isDarkTheme, statusViewMode, tableActionsAlignment } = body; + const { username, isDarkTheme, statusViewMode, tableActionsAlignment } = body; const existing = await prisma.user.findUnique({ where: { @@ -47,17 +46,12 @@ export class AccountController { throw new ExtendedBadRequest({ username: "userAlreadyExists" }); } - if (discordId && (await isDiscordIdInUse(discordId, user.id))) { - throw new ExtendedBadRequest({ discordId: "discordIdInUse" }); - } - const updated = await prisma.user.update({ where: { id: user.id, }, data: { username, - discordId: discordId || undefined, isDarkTheme, statusViewMode, tableActionsAlignment, diff --git a/packages/client/src/components/account/AccountSettingsTab.tsx b/packages/client/src/components/account/AccountSettingsTab.tsx index 875b8788c..9a6cf0d84 100644 --- a/packages/client/src/components/account/AccountSettingsTab.tsx +++ b/packages/client/src/components/account/AccountSettingsTab.tsx @@ -46,8 +46,8 @@ export function AccountSettingsTab() { - - + +
diff --git a/packages/client/src/lib/utils.ts b/packages/client/src/lib/utils.ts index 7b55efed8..b52f82785 100644 --- a/packages/client/src/lib/utils.ts +++ b/packages/client/src/lib/utils.ts @@ -145,3 +145,7 @@ export function formatOfficerDepartment(unit: FullOfficer | FullDeputy) { return getUnitDepartment(unit)?.value.value ?? null; } + +export function canUseDiscordAuth() { + return typeof window !== "undefined" && window.location === window.parent.location; +} diff --git a/packages/client/src/pages/account.tsx b/packages/client/src/pages/account.tsx index f595627ef..c332d22e3 100644 --- a/packages/client/src/pages/account.tsx +++ b/packages/client/src/pages/account.tsx @@ -13,6 +13,7 @@ import { useFeatureEnabled } from "hooks/useFeatureEnabled"; import { useMounted } from "@casper124578/useful"; import { Title } from "components/shared/Title"; import { toastError } from "lib/error"; +import { canUseDiscordAuth } from "lib/utils"; const AccountSettingsTab = dynamic(async () => { return (await import("components/account/AccountSettingsTab")).AccountSettingsTab; @@ -54,7 +55,7 @@ export default function Account() { { name: t("appearanceSettings"), value: "appearanceSettings" }, ]; - if (DISCORD_AUTH) { + if (DISCORD_AUTH && canUseDiscordAuth()) { TABS_TITLES[3] = { name: t("connections"), value: "connections" }; } diff --git a/packages/client/src/pages/auth/login.tsx b/packages/client/src/pages/auth/login.tsx index 48e9d1937..1ddc5276a 100644 --- a/packages/client/src/pages/auth/login.tsx +++ b/packages/client/src/pages/auth/login.tsx @@ -18,6 +18,7 @@ import { useFeatureEnabled } from "hooks/useFeatureEnabled"; import { Title } from "components/shared/Title"; import { AuthScreenImages } from "components/auth/AuthScreenImages"; import { TwoFactorAuthScreen } from "components/auth/TwoFactorAuthScreen"; +import { canUseDiscordAuth } from "lib/utils"; const INITIAL_VALUES = { username: "", @@ -139,7 +140,7 @@ export default function Login() {
- {DISCORD_AUTH ? ( + {DISCORD_AUTH && canUseDiscordAuth() ? ( <>