The Pinia stores are where the data of the backend lives on the frontend. The bootstrap request and the store key of any response fill them; components only read them and call their actions.

Registering stores

Response binds data only into the stores it knows. Register every store which receives a bootstrap section or a store key of a response:
plugins/01.app.js
addStores() takes store definitions (useEventStore), not instances (useEventStore()). They are resolved per response with the Pinia of the request, which is what makes them safe in SSR. A definition registered later under the same id replaces the earlier one. The Nuxt layer with bootstrap.enabled registers the helpers stores itself: app, auth, locale, ajax, otp, network. Apps without the layer register the ones they use.

One section, one store

The section event() of the bootstrap request fills the store event:
  • The store id equals the section name, in the singular.
  • Declare every property the backend sends in state(), with an empty default. The page renders before the bootstrap answers, and a declared property is reactive from the start.
  • A key of the section naming an action calls it with the value, see How store is bound.
  • A store which only holds local UI state is not registered.

Helpers stores

The app and auth stores match the sections of AdminHelpers\Utilities\BootstrapRequest: the app section returns booted and backendEnv, the auth section an AuthResponse. Read backend switches through useBackendEnv('KEY', default) instead of the store. The locale section must return translations; CrudadminVue and the Nuxt layer replace the catalog of __() whenever it changes:

Extending the helpers stores

app and auth are defined from options exported by @crudadmin/helpers/definitions. Define the store under the same id with your additions; your definition wins the auto-import and the layer uses it too:
app/store/authStore.js
app/store/appStore.js

Persistence

On the web (SSR) build the app and auth stores are not persisted: the token lives in a cookie, the server renders the logged in state, and the token is removed from the html payload. The SPA build persists them, with pinia-plugin-persistedstate. Project stores choose themselves with persist: true; persist only what the app needs before the first bootstrap answers.