Sessions and cookie context
A visitor can read the Journal before they sign in. By the time they save an article, the action needs to know which account is writing. We’ll choose what each route receives.
Choose what the handler receives
Look at the access setting on the operation in OpenAPI. It determines whether Bwf looks for a session, starts one for an anonymous reader, or requires a signed-in account. You’ll see that choice in the generated handler signature.
Read x-bwf-access
Which context fits this route? A health check can use public and take the configuration. With visitor you can read a session if one already exists. Use session when an anonymous reader needs one too. For an action that needs the account, signed-in supplies Controller.SignedIn.
Set this extension on an operation that needs an account.
x-bwf-access: signed-inFollow the cookie to its session row
Look at what the browser carries between requests. The cookie contains a token. The server uses it to find the session and check its expiration.
The session row can hold a CSRF token before anyone signs in. Sign-in rotates the tokens, and sign-out removes the session. See password authentication for the controller response.
In a development database, inspect the timestamps and account IDs without selecting the session or CSRF tokens.
SELECT user_id IS NOT NULL AS signed_in, expires_at
FROM bwf_sessions
WHERE expires_at > now();Read the account in a signed-in action
The router builds the signed-in context after it has authenticated the request. The application still decides ownership, membership and roles. See authorization and ownership for an article edit.
A signed-in controller can read the account ID with this call.
author_id = Controller.signed_in_user(context)