A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function.
I get this error in a composable I only use in a setup function, so I'm not really sure of why it appears.
Since it's used in a setup function, the nuxt app context should be available.
Even using runWithContext does not manage to fix the problem
Here is the code:
export default async function useUserList () {
const messages = useMessages()
const page = useState('page', () => 1)
const perPage = useState('perPage', () => 15)
const userCount = await useAuthenticatedFetch<number>('/api/users/count')
// ERROR HERE
// VVVVVVVVVVVV
const users = await useAsyncData('users', async () => {
const from = (page.value - 1) * perPage.value
const result = await useAuthenticatedFetch<User[]>(`/api/users?from=${from}&size=${perPage.value}`)
if (result.error.value) {
messages.showMessage({
message: result.error.value?.data.message ?? 'Une erreur est survenue',
type: NotificationType.ERROR
})
return
}
return result.data.value ?? []
})
return {
userCount,
users,
pending: computed(() => userCount.pending.value || users.pending.value),
page,
perPage
}
}
