feat: implement unified login flow with LoginButton and contextual LoginDialog for unauthenticated form access

This commit is contained in:
2026-07-03 23:18:59 +07:00 Unverified
parent ac6c35598c
commit 2e94c8f8ec
3 changed files with 44 additions and 29 deletions
+31 -24
View File
@@ -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 (
<div className="max-w-2xl mx-auto p-4 md:p-6 space-y-6">
<FormFillerClient
form={form}
questions={questionsList}
initialAnswers={initialAnswers}
/>
</div>
<>
<div className="max-w-2xl mx-auto p-4 md:p-6 space-y-6">
<FormFillerClient
form={form}
questions={questionsList}
initialAnswers={initialAnswers}
/>
</div>
{!discordId && <LoginDialog />}
</>
);
}