Username/password auth for Datasette with database-backed accounts in the internal DB, an admin permission, and a Svelte/Vite/TS frontend.
- Svelte 5 pages (
frontend/src/pages/{login,admin,account}) built by Vite intodatasette_accounts/static/gen/+manifest.json(shipped).routes/pages.pyrenderstemplates/accounts_base.html, which mounts the page bundle on#app-rootand reads#pageData. Pages call the JSON API viafrontend/src/lib/api.ts(postJSON), not openapi-fetch. - Rebuild the frontend after changing Svelte/TS:
just frontend(orjust typesfirst if page-data models changed).npm run checktype-checks.
__init__.py— hooks (routes, actions, permission SQL, startup, actor, menu, top_homepage for the bootstrap prompt + signed-out message, asgi_wrapper for forced password change, hash-password CLI).messages.py— admin-editable site-message slot registry + rendering (bodies are admin-authored raw HTML, rendered verbatim — admin-only editor);db.pysite_messagestable + get/set (blank clears).db.py— internal-DB access; namespaced tables; shared admin predicate; transactional mutations (audit-in-same-tx, last-admin guard). Pure orchestration over typed helpers generated bysolite codegenfromsql/queries.sql→sql/_queries_generated.py(seeplans/codegen/): reads run helpers inexecute_fn, atomic writes inexecute_write_fn; helpers return dataclasses,db.pyconverts to dicts. Timestamps are generated in SQL (strftime('%Y-%m-%dT%H:%M:%f','now')||'+00:00', relative deadlines viaprintf('%+d minutes', n)etc.), byte-identical todb.now_iso()(Python millisecond ISO) which remains only for read-side lock/expiry comparisons. Three acl-touching queries (acl_available,list_acl_groups,list_capability_grants) stay hand-written — they reference datasette-acl tables absent from our schema.passwords.py— PBKDF2 (copied from datasette-auth-passwords) + async wrappers (KDF runs off the event loop) + DUMMY_HASH + length bounds.security.py— CSRF gates,?next=validation, secure-cookie + IP-trust.router.py— shared Router + POST-only/CSRF/admin decorators.routes/api.py,routes/pages.py— endpoints and HTML shells.grantable.py— which global actions are grantable + principal gating + config-grant display;db.pycapability_grantstable + grant/revoke/list.__init__.permission_resources_sqlemits capability-grant allow rows (F1) and the acl-admin bridge (F2);datasette_acl_valid_actorsexposes accounts (F3). Frontend:frontend/src/pages/capabilities. datasette-paper is a dev dep used as the worked example (datasette-paper-create) in tests + screenshots.
- datasette-plugin-router does not dispatch by HTTP method: identical paths
collide (first wins for all methods), and mutation views also answer GET.
Mutation decorators therefore enforce POST-only; the logout page (GET
/-/logout) and mutation (POST/-/logout/perform) use distinct paths. permission_resources_sqlmust return aPermissionSQLwith a non-emptyparamsdict (includeactor_id) or core drops the bindings.datasette_vite.vite_entry(datasette, plugin_package, manifest_dir=None)— novite_dev_pathkwarg in the pinned version.
just test · just check · just format · just dev
just codegen-queries— regeneratesql/_queries_generated.pyafter editingsql/queries.sqlorinternal_migrations.py.just check-queries-freshis the CI gate (fails when the checked-in helper is stale). The codegen IR (sql/_queries.sql.json) is gitignored;soliteis a dev dep.