import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { cache } from "react";
import { auth } from "@/lib/auth";

export const requireSession = cache(async () => {
  const result = await auth.api.getSession({ headers: await headers() });
  if (!result) redirect("/sign-in");
  return result;
});
