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
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
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. Theirapp 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 ownAxios.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:
- Set
crudadmin.bootstrap.enabled, plusplatform.typeif the API serves more apps andcapacitor.enabledfor the native build. - Delete from the boot plugin
Axios.setOptions()(token, locale, platform headers), the helpers stores inResponse.setStores()andnew Capacitor(...). Register the project stores withResponse.addStores([...]), project headers withAxios.addHeaders(). - Delete the SSR fetch from
app.vue. - Delete the project
refreshApp(),getBootstrapResponse(),useBackendEnv()and the platform header helpers. Keep only project state, by extending the options from@crudadmin/helpers/definitionsunder the same store id. An after-refresh helper becomes acrudadmin:bootstraphook. - Extend
authStorefrom@crudadmin/helpers/definitionswith the project getters. Logout goes throughuseAuth().logout(), project clean up moves to thecrudadmin:auth:logouthook. Keep project specific getters such as aloggedInrequiring a completed registration. - The web build keeps the token in the
auth_tokencookie and no longer persists theauthstore, so web users log in again once. SPA users stay logged in. - A project with its own
useAuthshadows the helpers one. Rename it, or make it a thin wrapper.
MIGRATION-2.0-to-2.1.md has the full list.