26 lines
653 B
TypeScript
26 lines
653 B
TypeScript
"use server"
|
|
|
|
import { cookies } from "next/headers"
|
|
import prisma from "@/lib/prisma"
|
|
|
|
export async function verifyPlanPassword(planId: string, password: string) {
|
|
const plan = await prisma.plan.findUnique({
|
|
where: { id: planId },
|
|
})
|
|
|
|
if (!plan) return false
|
|
|
|
if (plan.password === password) {
|
|
// Set a simple cookie to authorize this plan
|
|
(await cookies()).set(`plan_auth_${planId}`, "true", {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
maxAge: 60 * 60 * 24 * 30, // 30 days
|
|
path: "/",
|
|
})
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|