Passer au contenu principal

Documentation Index

Fetch the complete documentation index at: https://kubo-47e69177.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Auth Patterns

Configurer le contexte

app/bootstrap.server.ts
import { setActionContext } from "@zapaction/core";

setActionContext(async () => {
  const session = { user: { id: "u_123", role: "admin" } };

  if (!session.user) {
    throw new Error("Unauthorized");
  }

  return {
    userId: session.user.id,
    role: session.user.role
  };
});

Wrapper d’action protegee

app/protected-action.ts
import { defineAction, type DefineActionOptions } from "@zapaction/core";

type AppContext = { userId: string; role: "admin" | "user" };

export function protectedAction<TInput, TOutput>(
  options: DefineActionOptions<TInput, TOutput, AppContext>
) {
  return defineAction<TInput, TOutput, AppContext>({
    ...options,
    beforeAction: async (args) => {
      if (!args.ctx.userId) throw new Error("Unauthorized");
      await options.beforeAction?.(args);
    }
  });
}