Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

673 B
Raw Blame
"use server";

import { prisma } from "@/lib/prisma";
import { cookies } from "next/headers";

export async function verifyPassword(_prevState: any, data: FormData) {
  const dashboardId = data.get("dashboardId") as string;
  const password = data.get("password") as string;

  const dashboard = await prisma.dashboard.findUnique({
    where: { id: dashboardId },
  });

  if (!dashboard) {
    return { error: "Dashboard not found" };
  }

  if (dashboard.password !== password) {
    return { error: "Invalid password" };
  }

  (await cookies()).set(`dub_password_${dashboardId}`, password, {
    path: "/",
    httpOnly: true,
    secure: true,
  });

  return true;
}