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.
| Question | Package / hook | Where it runs | Failure behavior |
|---|---|---|---|
| Valid session on this request? | foldkit-auth (AuthServer.resolver) | Server per request | 401 Unauthenticated before reads |
Who is the session (User, role)? | Your principal callback | Server per request | 401 if callback refuses session |
| Which rows and fields can they read? | foldkit-guard (Read rules) | Server SQL or evaluator | Filtered out silently |
| May they execute this write? | foldkit-guard (Write rules) | Server before/in write | 403 Forbidden |
| What may the UI draw as allowed? | Me and row may hints | Server computes; client reads | Button hidden; server re-checks |
| Sign-in, sign-out, cookies | Yielded Auth | Auth routes | PasswordRejected, 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-authreturns401only 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.