Skip to main content

Crate pocopine_auth

Crate pocopine_auth 

Source
Expand description

Native auth contracts for pocopine server functions.

The crate stays provider-neutral. Pocopine’s generated server routes build a host-only request context before decoding the server-function body; host middleware can validate a session/JWT/provider token and insert an AuthUser or Principal into request extensions. Guards then inspect that context through ordinary Rust functions.

§Module layout

Structs§

AuthError
Auth provider failure.
AuthUser
Authenticated application user.
Permission
Permission attached to an authenticated user.
Principal
Request principal. Anonymous requests have no user, but the type still exposes role/permission probes so guard closures stay ergonomic.
RequestContext
Request metadata available to server-function auth guards.
Role
Role attached to an authenticated user.
Session
Auth session metadata.

Enums§

Decision
Outcome of a Predicate check against a Principal.
DenyReason
Closed-set reason carried by Decision::Deny.

Constants§

SESSION_COOKIE
Default session cookie name used by the simple auth helpers.

Traits§

AuthProvider
Auth provider contract. Clerk/Auth0/Supabase adapters can implement this without changing the server-function guard ABI.
Predicate
Sync, cross-target permission check against a Principal.
SessionStore
Session persistence contract for first-party/simple auth.

Functions§

all_of
Predicate that allows only when both child predicates allow. Returns the first Deny reason (short-circuits).
any_of
Predicate that allows when either child predicate allows. Tries p first; if p denies, tries q. The reason on Deny is the second predicate’s reason — the assumption is the broader (latter) check carries the more useful user-visible failure.
ensure_login
Ensure the request is authenticated.
ensure_permission
Ensure the request has a permission.
ensure_role
Ensure the request has a role.
require_admin
Built-in #[server(guard = ...)] guard requiring the conventional admin role (matched by string).
require_auth
Predicate matching any authenticated user.
require_login
Built-in #[server(guard = ...)] guard requiring any logged-in user.
require_permission
Predicate matching any user holding permission (string match).
require_role
Predicate matching any user holding role (string match).
require_staff
Built-in #[server(guard = ...)] guard requiring the conventional staff role (matched by string).

Type Aliases§

AuthFuture
Boxed async result used by provider traits without choosing an async-trait dependency.
AuthResult
Provider/session result type.