Merge pull request #515 from erzabytyci/user-tiers

make talback admin only
This commit is contained in:
erzabytyci
2026-05-19 10:16:41 +03:00
committed by GitHub
2 changed files with 50 additions and 27 deletions
+9 -2
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { withAuth } from "@/backend/middleware/withAuth";
import sendEmail from "@/backend/mailService";
const talkbackSchema = z.object({
@@ -18,7 +19,8 @@ const talkbackSchema = z.object({
.max(2000, "Nachricht ist zu lang."),
});
export async function POST(req) {
export const POST = withAuth(
async (req) => {
try {
const body = await req.json();
const result = talkbackSchema.safeParse(body);
@@ -51,4 +53,9 @@ export async function POST(req) {
{ status: 500 }
);
}
}
},
{
requireAuth: true,
requireAdmin: true,
}
);
+16
View File
@@ -2,10 +2,26 @@
import "./talkback.css";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { Button } from "@/components/ui/button";
import { withBasePath } from "@/shared/utils/basePath";
import { useIsAdmin } from "@/context/user.context";
export default function TalkbackPage() {
const isAdmin = useIsAdmin();
const router = useRouter();
useEffect(() => {
if (isAdmin === false) {
router.replace(withBasePath("/"));
}
}, [isAdmin, router]);
if (isAdmin !== true) {
return null;
}
const defaultSubject = "Rückmeldung von GRADESA 2.0";
const [email, setEmail] = useState("");