Auth.Session
Auth
Signed cookie sessions and opaque session-id cookie helpers.
**Signed claims** (default): mint an HS256 JWT into a cookie with purpose = "session". **Opaque**: set/read a raw session secret (todo-app style); the app owns DB lookup and RLS.
Types
Config
type Config = Config { secret : String
, cookieName : String
, ttlSeconds : Int
, attrs : { httpOnly : Bool
, secure : Bool
, path : String
, sameSite : String
, maxAge : Maybe Int
}
}Session cookie configuration.
Examples
Auth.Session.config
{ secret = "…", cookieName = "_session", ttlSeconds = 86400 }Values
config
config : { secret : String , cookieName : String , ttlSeconds : Int } -> ConfigBuild a session config. Uses Cookies.defaults for cookie attributes (HttpOnly, Path=/, SameSite=Lax).
Examples
session =
Auth.Session.config
{ secret = env.secret
, cookieName = "_session"
, ttlSeconds = 86400
}withAttrs
withAttrs : { httpOnly : Bool , secure : Bool , path : String , sameSite : String , maxAge : Maybe Int } -> Config -> ConfigOverride Set-Cookie attributes (for example Secure on HTTPS).
Examples
Auth.Session.withAttrs Cookies.secureDefaults sessionsign
sign : Config -> claims -> HeaderMint a signed session cookie header for claims.
Examples
Auth.Session.sign session { userId = "42" }verify
verify : Config -> Request -> Maybe claimsRead and verify a signed session cookie. Returns claims when the JWT is valid and purpose is session.
Examples
Auth.Session.verify session reqclear
clear : Config -> HeaderClear the session cookie.
Examples
Auth.Session.clear sessionputOpaque
putOpaque : Config -> String -> HeaderSet an opaque session id / secret as the cookie value.
Examples
Auth.Session.putOpaque session sessionIdgetOpaque
getOpaque : Config -> Request -> Maybe StringRead the opaque cookie value (no crypto).
Examples
Auth.Session.getOpaque session req