POST (unsubscribe/route.ts)

MokerSaaS · app/api/newsletter/unsubscribe/route.ts · typescript · MIT
email

Handles newsletter unsubscribe via POST and GET, validating input, updating DB, and returning localized responses.

// Source: https://github.com/ItusiAI/MokerSaaS | License: MIT | Copyright 2026 ItusiAI
// Provided via justclaw.it.com; keep this notice with the code.
import { NextRequest, NextResponse } from 'next/server'
import { db } from '@/lib/db'
import { newsletterSubscriptions } from '@/lib/schema'
import { eq } from 'drizzle-orm'
import { getTranslations } from 'next-intl/server'

const SUPPORTED_LOCALES = ['en', 'zh-CN', 'ja', 'ko', 'zh-TW'] as const
type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]

function pickLocale(input: unknown): SupportedLocale {
  if (typeof input === 'string' && (SUPPORTED_LOCALES as readonly string[]).includes(input)) {
    return input as SupportedLocale
  }
  return 'en'
}

export async function POST(request: NextRequest) {
  try {
    const body = await r

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key