Add a staff sign-in to an application
Use this when part of an application is for the owner’s own people: an order board, an admin list, a back office. Visitors keep using the public pages without an account. Staff sign in with an email and a password. There is no self-registration and there are no roles: anyone signed in is staff.
Everything here is done through the hosted MCP tools. No API key and no console step is needed.
1. Three models
Section titled “1. Three models”Create and publish all three. The field names of the session model are fixed; use them exactly.
Identity model, for example app_user. Private: no anonymous read or create.
| Field | Type | Settings |
|---|---|---|
email |
varchar | required, unique |
password |
varchar | required, {"credential_strategy": "password_hash"} |
display_name |
varchar | required |
Session model, for example app_session. Private, with model settings {"records_api": "off"} so no page or caller can list sessions.
| Field | Type |
|---|---|
identity_record_id |
uuid |
jti |
uuid |
status |
text |
issued_at |
timestamp |
expires_at |
timestamp |
last_seen_at |
timestamp |
revoked_at |
timestamp |
token_version |
integer |
Login submission model, for example login_submission, with two required varchar fields, email and password. It is the only one of the three that visitors may write to. Create it with anonymous_create: true and model settings that include:
{"login_submission": true}That flag is what makes a create on this model a sign-in attempt and not a stored record. Add a logout_submission model the same way, with no fields and {"logout_submission": true}, for the sign-out button.
2. Tell the application which models they are
Section titled “2. Tell the application which models they are”Call update_application with the identity model and the identity settings. Field mappings take the field ids returned by add_field, not field names.
{ "identityModelId": "<identity model id>", "identitySettings": { "field_mappings": { "email": "<email field id>", "password": "<password field id>", "display_name": "<display_name field id>" }, "session_model_id": "<session model id>", "login_submission_model_id": "<login submission model id>", "registration_enabled": false, "registration_email_verification": "off", "password_min_length": 12 }}registration_enabled: false is what keeps the public from creating accounts. identitySettings is replaced as a whole, so always send the complete object. Do not add mappings for the session model’s fields.
3. The login page
Section titled “3. The login page”Create a page whose slug is exactly login. A signed-out visitor who opens a page that requires sign-in is sent to /login, and that route is not configurable.
{ "id": "login-form", "type": "form", "source": { "model_id": "<login submission model id>", "target_mode": "create", "on_success_toast": "Signed in.", "on_success_redirect": "/board" }, "blocks": [ {"id": "login-email", "type": "input", "binding": {"field": "email", "save_mode": "submit"}, "content": {"label": "Email", "required": true}, "display": {"type": "email"}}, {"id": "login-password", "type": "input", "binding": {"field": "password", "save_mode": "submit"}, "content": {"label": "Password", "required": true}, "display": {"type": "password"}}, {"id": "login-submit", "type": "button", "content": {"label": "Sign in"}, "display": {"type": "submit"}} ]}The sign-out button is a form on any signed-in page, bound to the logout submission model:
{ "id": "signout-form", "type": "form", "source": {"model_id": "<logout submission model id>", "target_mode": "logout", "on_success_redirect": "/"}, "blocks": [ {"id": "signout-submit", "type": "button", "content": {"label": "Sign out"}, "display": {"type": "submit"}} ]}4. Pages that require sign-in
Section titled “4. Pages that require sign-in”Set the page’s settings with create_page or update_page, then publish the page:
{"requires_auth": true}A page left as a draft answers “Unable to load published page” to everyone, signed in or not. Publish the login page and every protected page.
5. What staff may read and change
Section titled “5. What staff may read and change”Signing in does not open a private model. On each model the staff pages show, set what a signed-in user may do, merged with the settings the model already has:
{"consumer_reads": "any_authenticated", "consumer_writes": "any_authenticated"}Leave consumer_writes out on a model staff should only read. A model the public writes to, such as an order form’s model, keeps its anonymous_access.create: true; that setting is separate and still applies.
6. Create the staff account
Section titled “6. Create the staff account”With registration off, the owner’s assistant creates each account. Call create_record on the identity model:
{"email": "staff@example.com", "password": "<a password of at least 12 characters>", "display_name": "Staff"}The password is stored hashed and is never returned by a read. Generate a strong one, give it to the owner once in your reply, and tell them to change it. To add another staff member later, create another record the same way.
7. Check it
Section titled “7. Check it”Open the protected page signed out: you must land on /login. Sign in with the staff account: you must land on the page named in on_success_redirect and see the data. Open the login page signed out and confirm there is no way to register.
A note on applications with an uploaded site
Section titled “A note on applications with an uploaded site”The docs say an application that serves an uploaded site closes its generic record routes to visitors. That applies only to applications with a hosted site enabled. An application built from platform pages, as in this recipe, is not affected: its public pages and public forms keep working for signed-out visitors.
