- NextAuth v5 with email+password credentials, JWT sessions - Registration, login, email verification, password reset flows - Stripe integration: Free (15/day), Starter ($5/1k/mo), Pro ($20/100k/mo) - API key management (cb_ prefix) with hash-based validation - Dashboard with generations history, settings, billing management - Rate limiting: Redis daily counter (free), DB monthly (paid) - Generate route auth: Bearer API key + session, anonymous allowed - Worker userId propagation for generation history - Pricing section on landing page, auth-aware navbar - Middleware with route protection, CORS for codeboard.vectry.tech - Docker env vars for auth, Stripe, email (smtp.migadu.com)
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import crypto from "crypto";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const rawToken = request.nextUrl.searchParams.get("token");
|
|
|
|
if (!rawToken) {
|
|
return NextResponse.redirect(new URL("/login?error=missing-token", request.url));
|
|
}
|
|
|
|
const tokenHash = crypto.createHash("sha256").update(rawToken).digest("hex");
|
|
|
|
const verificationToken = await prisma.emailVerificationToken.findUnique({
|
|
where: { token: tokenHash },
|
|
include: { user: true },
|
|
});
|
|
|
|
if (!verificationToken) {
|
|
return NextResponse.redirect(new URL("/login?error=invalid-token", request.url));
|
|
}
|
|
|
|
if (verificationToken.used) {
|
|
return NextResponse.redirect(new URL("/login?verified=true", request.url));
|
|
}
|
|
|
|
if (verificationToken.expiresAt < new Date()) {
|
|
return NextResponse.redirect(new URL("/login?error=token-expired", request.url));
|
|
}
|
|
|
|
await prisma.$transaction([
|
|
prisma.user.update({
|
|
where: { id: verificationToken.userId },
|
|
data: { emailVerified: true },
|
|
}),
|
|
prisma.emailVerificationToken.update({
|
|
where: { id: verificationToken.id },
|
|
data: { used: true },
|
|
}),
|
|
]);
|
|
|
|
return NextResponse.redirect(new URL("/login?verified=true", request.url));
|
|
}
|