auth.getSession
Puck Auth is experimental and may change in a future release.
Get the session of a user signed in with Puck Auth.
await puck.auth.getSession(await headers());
// { user: { id: "user_123", name: "Jane Doe", email: "jane@example.com", image: null }, expiresAt: "2026-10-30T12:00:00.000Z" }Returns a PuckSession, or null if the user is signed out.
Args
| Param | Example | Type | Status |
|---|---|---|---|
headersOrRequest | await headers() | Request | Headers | Required |
options | { apiKey: "SECRET" } | Object | - |
headersOrRequest
The incoming request, or its headers. For example, the result of Next’s headers().
import puckCloud from "@puckeditor/cloud-client";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
const puck = puckCloud();
export default async function Page() {
const session = await puck.auth.getSession(await headers());
if (!session) {
return new Response("Unauthorized", { status: 401 });
}
return <Editor />;
}options
Set the request options for this call.