Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

497 B
Raw Blame
import { auth } from "@/lib/auth/auth";
import { headers } from "next/headers";
import { cache } from "react";

/**
 * Reads the Better Auth session for the current request. React-cached so
 * repeated calls within one request hit the DB (or cookie cache) once.
 */
export const getServerSession = cache(async () => {
  try {
    return await auth.api.getSession({ headers: await headers() });
  } catch (error) {
    console.error("Failed to read auth session:", error);
    return null;
  }
});