diff --git a/app/form/[id]/page.tsx b/app/form/[id]/page.tsx index 0a1ffbf..e4ad9b9 100644 --- a/app/form/[id]/page.tsx +++ b/app/form/[id]/page.tsx @@ -4,6 +4,7 @@ import { getServerSession } from "next-auth"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { notFound } from "next/navigation"; import { getGuildMemberRoles } from "@/app/actions/discord"; +import LoginDialog from "@/components/login-dialog"; export const dynamic = "force-dynamic"; @@ -24,26 +25,29 @@ export default async function FormsSubmitPage( return notFound(); } - if (discordId) { - const allowedRoles = form.allowedRoles || []; - const deniedRoles = form.deniedRoles || []; + const allowedRoles = form.allowedRoles || []; + const deniedRoles = form.deniedRoles || []; + const hasRoleRestrictions = allowedRoles.length > 0 || deniedRoles.length > 0; - if (allowedRoles.length > 0 || deniedRoles.length > 0) { - const userRoles = await getGuildMemberRoles(discordId); - - let isAllowed = allowedRoles.length === 0; - if (allowedRoles.length > 0) { - isAllowed = userRoles.some(r => allowedRoles.includes(r)); - } + if (hasRoleRestrictions) { + if (!discordId) { + return notFound(); + } - let isDenied = false; - if (deniedRoles.length > 0) { - isDenied = userRoles.some(r => deniedRoles.includes(r)); - } + const userRoles = await getGuildMemberRoles(discordId); + + let isAllowed = allowedRoles.length === 0; + if (allowedRoles.length > 0) { + isAllowed = userRoles.some(r => allowedRoles.includes(r)); + } - if (!isAllowed || isDenied) { - return notFound(); - } + let isDenied = false; + if (deniedRoles.length > 0) { + isDenied = userRoles.some(r => deniedRoles.includes(r)); + } + + if (!isAllowed || isDenied) { + return notFound(); } } @@ -70,12 +74,15 @@ export default async function FormsSubmitPage( } return ( -