Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { hashVerificationToken } from "@/lib/email-verification";
|
|
import { getBaseUrl } from "@/lib/url";
|
|
|
|
export async function GET(request: Request) {
|
|
const token = new URL(request.url).searchParams.get("token");
|
|
const baseUrl = getBaseUrl();
|
|
const fail = (message: string) =>
|
|
NextResponse.redirect(`${baseUrl}/konto?error=${encodeURIComponent(message)}`);
|
|
|
|
if (!token) {
|
|
return fail("Dieser Bestätigungslink ist ungültig.");
|
|
}
|
|
|
|
const verificationToken = await prisma.emailVerificationToken.findUnique({
|
|
where: { tokenHash: hashVerificationToken(token) },
|
|
});
|
|
|
|
const isValid =
|
|
verificationToken && verificationToken.usedAt === null && verificationToken.expiresAt > new Date();
|
|
if (!isValid) {
|
|
return fail("Dieser Bestätigungslink ist ungültig oder abgelaufen. Bitte fordere über /konto einen neuen an.");
|
|
}
|
|
|
|
await prisma.$transaction([
|
|
prisma.customer.update({
|
|
where: { id: verificationToken.customerId },
|
|
data: { emailVerifiedAt: new Date() },
|
|
}),
|
|
prisma.emailVerificationToken.update({
|
|
where: { id: verificationToken.id },
|
|
data: { usedAt: new Date() },
|
|
}),
|
|
]);
|
|
|
|
return NextResponse.redirect(
|
|
`${baseUrl}/konto?message=${encodeURIComponent("Deine E-Mail-Adresse wurde bestätigt.")}`
|
|
);
|
|
}
|