The Nuxt layer boots every app the same way: axios defaults, the auth token, one bootstrap request filling the stores and its periodic refresh. A project only registers its own stores. The boot is off by default; turn it on in nuxt.config.

Configuration

nuxt.config.ts
platform.type is sent as the app-type header. The backend selects the bootstrap class by it when one API serves several apps, see Several applications.

What happens on boot

The bootstrap is fetched in app:created, after every plugin, so the stores and headers registered by plugins of other layers and of the project are in place.

Plugin order

Numbered plugins (NN.name.js) of every layer extending helpers run in the order of their numbers right after Pinia, before the Nuxt core plugins and before the plugins of the project: helpers 00-09, eshop 10-19. Do not use the router in them, use a hook. The plugins of the project itself are never reordered.

Registering project stores

The only boot code a project needs is a plugin registering the stores which receive the bootstrap sections:
plugins/01.app.js
See Pinia stores for the rules of Response.addStores().

Refreshing

useAppStore().refreshApp(only) does the same and is what the network refresher calls. The browser refresher runs on reconnect and every refreshSeconds; the backend can change the interval with backendEnv.APP_REFRESH_SECONDS.

Hooks

Code which has to run after every bootstrap (registering push notifications, checking a version) belongs in the crudadmin:bootstrap hook. Clean up of project stores after a logout belongs in crudadmin:auth:logout.

Auth

Every response of useAuth() is applied like a bootstrap: the store sections the backend adds to a login reach their stores (for example the e-shop cart after merging the guest cart), and an AuthResponse in data fills the auth store. So both login responses of crudadmin/helpers work, the default one and admin_helpers.auth.response = 'bootstrap'. Errors are thrown to the caller.

Where the token lives

A revoked token does not answer 401 on the bootstrap, which is optionally authenticated; it answers as a guest. The layer then sees an auth section without a user and forgets the token. A 401 from any other request logs the user out when logoutOnUnauthorized is on.

Helpers composables

All auto-imports of the layer have a lower priority than the project, so a project exporting the same name keeps its own.

Without the Nuxt layer

Vite, Ionic and Vue apps without Nuxt boot by hand. Their app store fetches the bootstrap and hands the response to useResponse():
src/stores/app.js
Capacitor from @crudadmin/helpers/capacitor calls refreshApp() on start, on reconnect and periodically. See the installation in @crudadmin/helpers.

Moving an older project onto the layer boot

Projects started before helpers 2.1 boot themselves: their own Axios.setOptions(), Response.setStores(), appStore.refreshApp(), an SSR useAsyncData('app-bootstrap') in app.vue and new Capacitor(...). It keeps working, the layer boot is opt-in. To move a project:
  1. Set crudadmin.bootstrap.enabled, plus platform.type if the API serves more apps and capacitor.enabled for the native build.
  2. Delete from the boot plugin Axios.setOptions() (token, locale, platform headers), the helpers stores in Response.setStores() and new Capacitor(...). Register the project stores with Response.addStores([...]), project headers with Axios.addHeaders().
  3. Delete the SSR fetch from app.vue.
  4. Delete the project refreshApp(), getBootstrapResponse(), useBackendEnv() and the platform header helpers. Keep only project state, by extending the options from @crudadmin/helpers/definitions under the same store id. An after-refresh helper becomes a crudadmin:bootstrap hook.
  5. Extend authStore from @crudadmin/helpers/definitions with the project getters. Logout goes through useAuth().logout(), project clean up moves to the crudadmin:auth:logout hook. Keep project specific getters such as a loggedIn requiring a completed registration.
  6. The web build keeps the token in the auth_token cookie and no longer persists the auth store, so web users log in again once. SPA users stay logged in.
  7. A project with its own useAuth shadows the helpers one. Rename it, or make it a thin wrapper.
The package file MIGRATION-2.0-to-2.1.md has the full list.