Generate experiences with Puck AI
Read docs
CloudAuthentication & identity

Authentication & identity

Puck Cloud implements endpoints and resources that need be authenticated to protect and isolate data between your users.

Authentication

puckHandler endpoints are open to anyone by default. To add your own authentication, check each request before running puckHandler:

const handleRequest = (request) => {
  const isAuthenticated = customAuthCheck(request);
 
  if (!isAuthenticated) {
    return new Response("Unauthorized", { status: 401 });
  }
 
  return puckHandler(request);
};

Or use Puck Auth to let users sign in with their Puck Cloud account.

Identity

By default, Puck Cloud doesn’t record who saves a change. To record it, provide auth.identity to both puckHandler and any server APIs:

const auth = {
  identity: {
    id: "my-user-id", // A unique ID from your system
    name: "Jane Smith",
    // ...any other data to store
  },
};
 
// Provide auth to your puckHandler if using plugins
const handleRequest = (request) => {
  return puckHandler(request, {
    auth,
  });
};
 
// Provide auth to last arg of server APIs
const page = await puck.pages.create({ path: "/about", data }, { auth });

Puck Cloud returns identity.id as createdBy on relevant resources.

Multi-tenancy

For multi-tenant apps, set auth.tenantId to isolate data between users:

const auth = {
  tenantId: "customer-1", // Isolates pages, chats and attachments to this tenant
};
 
const handleRequest = (request) => {
  return puckHandler(request, { auth });
};
 
const page = await puck.pages.getPublished("/about", { auth });

Further reading