Skip to content

Commit

Permalink
🔨 fix: remove ability to update discordId as user & hide Discord oaut…
Browse files Browse the repository at this point in the history
…h when in iframe
  • Loading branch information
casperiv0 committed Feb 10, 2022
1 parent fb9ccdf commit 24089c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 1 addition & 7 deletions packages/api/src/controllers/auth/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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: {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/account/AccountSettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export function AccountSettingsTab() {
<Input value={values.username} onChange={handleChange} name="username" />
</FormField>

<FormField optional label="Discord ID" errorMessage={errors.discordId}>
<Input value={values.discordId} onChange={handleChange} name="discordId" />
<FormField optional label="Discord ID">
<Input readOnly disabled value={values.discordId} />
</FormField>

<div className="flex items-center gap-2">
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion packages/client/src/pages/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" };
}

Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down Expand Up @@ -139,7 +140,7 @@ export default function Login() {
</Button>
</div>

{DISCORD_AUTH ? (
{DISCORD_AUTH && canUseDiscordAuth() ? (
<>
<hr className="my-5 border-[1.5px] rounded-md border-gray-3" />

Expand Down

0 comments on commit 24089c1

Please sign in to comment.