Verify requests and sessions
Admit protected requests using a fresh verified session and exact trusted origins.
Construct the request guard
Supply a SessionAdapter from your identity provider. Resolve fresh server state; provider unavailability must not become an anonymous fallback.
import { createRequestAccess, type SessionAdapter } from "@smoothie-framework/auth";
export function createAccess(sessions: SessionAdapter) {
return createRequestAccess({
sessions,
trustedOrigins: ["https://app.example.com"],
});
}Authenticate before reading the body
With Elysia, connect access.admit to a Service whose context provider requires AuthSession. Admission runs before bounded decoding and passes the identity only to that request.
// app, protectedService and access are server-owned dependencies.
mountService(app, protectedService, {
admit: ({ request }) => access.admit(request),
});Other hosts can use authenticate and accessErrorResponse directly. Missing/expired identity returns 401, rejected origin 403, and unavailable authentication 503. None of these responses proves resource authorization.
Check resource permissions inside the host/domain boundary before reading or mutating private data. Never pass provider tokens or cookies into Agent requestContext or model messages.