Stuart Clark (Deciphered): Druxt 0.25.2; Drupal Canvas sites, no Drupal required

Register a plugin like this one under plugins in nuxt.config.js, reading the token from wherever your site stores it:
0.25.0 added a server cache for the JSON:API index and menus. It skips any request that carries credentials, but it only saw a token added by an Axios interceptor once the response came back. Until then, a signed-in visitor could get a response cached for anonymous visitors. 0.25.2 runs your request interceptors on a copy of each request before it checks the cache, so the cache turns off from the first request (#1018).
If an interceptor has side effects, such as logging, it can skip that dry run by checking config[Symbol.for('druxt.processCache.probe')]. If an interceptor is an async function, the cache skips it and only sees its token when the first response arrives, so set that token on the Axios defaults instead. @nuxtjs/auth-next already does this unless token.global is off. Menus work the same way, including when an interceptor adds credentials only to menu requests.

Similar Posts