spaceship_helm/session
Types
Session storage backend.
pub type SessionStore {
SessionStore(data: dynamic.Dynamic)
}
Constructors
-
SessionStore(data: dynamic.Dynamic)
Values
pub fn commit(
resp: response.Response(body),
session: Session,
store: SessionStore,
) -> response.Response(body)
Save session and return the response.
This is a convenience function for saving session values:
let session = sessions.set_value(session, "username", "alice")
sessions.commit(response, session, store)
pub fn cookie(
cookie_name: String,
secret: String,
store: SessionStore,
) -> fn(
types.Context,
fn(types.Context) -> response.Response(BitArray),
) -> response.Response(BitArray)
Create a cookie-based session middleware.
This middleware:
- Reads the session ID from the cookie
- Loads the session data from the store
- Makes the session available via
sessions.get(ctx) - Saves the session data when the response is sent
Arguments
cookie_name- Name of the session cookie (e.g., “session_id”)_secret- Secret key for signing the session ID (reserved for future use)store- Session storage backend
pub fn get(ctx: types.Context, f: fn(Session) -> a) -> a
Get the session from the context.
This function is used with use syntax in handlers:
use session <- sessions.get(ctx)
let username = sessions.get_value(session, "username")
pub fn get_value(
session: Session,
key: String,
) -> option.Option(String)
Get a value from the session.