From 188deb1a91032164324d20570e7994f574c00de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Znamen=C3=A1=C4=8Dek?= Date: Thu, 21 Nov 2024 14:51:21 +0100 Subject: [PATCH] Fix payload decoding in newsletter subscribe endpoint --- app/account/newsletters/subscribe/route.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/account/newsletters/subscribe/route.ts b/app/account/newsletters/subscribe/route.ts index c3839d76..6b2d2b35 100644 --- a/app/account/newsletters/subscribe/route.ts +++ b/app/account/newsletters/subscribe/route.ts @@ -1,6 +1,6 @@ import { NextResponse, type NextRequest } from "next/server"; -import { boolean, optional, record, string } from "typescript-json-decoder"; +import { literal, optional, record, string } from "typescript-json-decoder"; import { subscribeToList } from "~/src/ecomail"; @@ -22,7 +22,7 @@ export async function POST(request: NextRequest): Promise { // Decode form data // const decodeRequest = record({ - acceptTerms: optional(boolean), + acceptTerms: optional(literal("on")), email: string, }); @@ -35,7 +35,7 @@ export async function POST(request: NextRequest): Promise { return new Response("Request invalid", { status: 400 }); } - if (requestData.acceptTerms === true) { + if (requestData.acceptTerms === "on") { console.info("Bot subscribe detected, ignoring."); return new Response("User subscription was successful, LOL", { status: 200,