Auth / Auth and Guard

How Auth and Guard split responsibility

A request enters foldkit-auth, which verifies the cookie/CSRF header and builds your principal; that principal then passes to foldkit-guard, which filters readable rows, checks write permissions, and computes UI may hints.

QuestionPackage / hookWhere it runsFailure behavior
Valid session on this request?foldkit-auth (AuthServer.resolver)Server per request401 Unauthenticated before reads
Who is the session (User, role)?Your principal callbackServer per request401 if callback refuses session
Which rows and fields can they read?foldkit-guard (Read rules)Server SQL or evaluatorFiltered out silently
May they execute this write?foldkit-guard (Write rules)Server before/in write403 Forbidden
What may the UI draw as allowed?Me and row may hintsServer computes; client readsButton hidden; server re-checks
Sign-in, sign-out, cookiesYielded AuthAuth routesPasswordRejected, etc.

Two rules keep the boundary clean:

  • A visitor is valid, not a 401: A request with no cookie resolves to Option.none(), and guard rules decide what public rows a visitor may read. foldkit-auth returns 401 only for expired/invalid sessions or missing CSRF headers.
  • Auth authenticates; Guard authorizes: Resolve identity in principal, and keep role or ownership checks inside your guard set so Remote, Sync, and agents enforce the same policy.