Closed matt-clegg closed 10 months ago
Hi @matt-clegg
Try to not use useAsyncData
in your plugins, this composable should be used only inside Pages or components.
As you are using useState
, you can leverage this to know if the store has been filed during SSR for hydration.
Thanks for the reply @Atinux, useAsyncData
was the culprit, thanks!
I'm trying to load some user roles and permission data when the Nuxt page first loads. I'm doing this in a
roles.ts
plugin.This plugin has been using the following composable:
I originally started by just making a call to load data from the
user-role
table. This was working fine. I would refresh the page and the data would be loaded on the server and included in the__NUXT_DATA__
payload.However, when I added a second call to load permission data from a different table, the page would return a 500 error
A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function
.I'm a bit confused as to why the plugin breaks when I include the second load call. The code above will work if you comment out the
await loadPermissions(rolesState.value.role);
line in the loadData function of the plugin.