Skip to content

Commit

Permalink
Fix payload decoding in newsletter subscribe endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zoul committed Nov 21, 2024
1 parent 878e513 commit 188deb1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/account/newsletters/subscribe/route.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -22,7 +22,7 @@ export async function POST(request: NextRequest): Promise<Response> {
// Decode form data
//
const decodeRequest = record({
acceptTerms: optional(boolean),
acceptTerms: optional(literal("on")),
email: string,
});

Expand All @@ -35,7 +35,7 @@ export async function POST(request: NextRequest): Promise<Response> {
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,
Expand Down

0 comments on commit 188deb1

Please sign in to comment.