Integrations

Nuxt

title: Nuxt description: Deep integration for Nuxt applications.

title: Nuxt description: Deep integration for Nuxt applications.

The @ginjou/nuxt module provides first-class support for Nuxt 3 or 4, including SSR-ready composables and automatic provider configuration.

Installation

Ginjou relies on @tanstack/vue-query for robust data fetching, caching, and state synchronization.
pnpm add @ginjou/nuxt @tanstack/vue-query

Setup

To set up the Ginjou in your Nuxt application, you need to register the module in your configuration and initialize the required providers in your root component.

Configuration

Add the module to your nuxt.config.ts:

export default defineNuxtConfig({
    modules: [
        '@ginjou/nuxt'
    ],
})

Providers

Ginjou uses a Context API pattern to provide configuration to your application. Instead of a single monolithic plugin, you use granular define*Context functions within the setup block of your root component.

Available setup functions:

FunctionDescription
defineFetchersContextProvide your data fetchers.
defineQueryClientContextProvide the TanStack Query client.
defineResourceContextProvide resource definitions and patterns.
defineAuthContextProvide the authentication provider.
defineAuthzContextProvide the authorization provider.
defineI18nContextProvide the internationalization provider.
defineNotificationContextProvide the notification provider.
defineRouterContextNot need, it'll automatically configured by the module.

Import and call your definition functions within the <script setup> block of your root component.

Here is a example of a root component (app/app.vue) configured with common providers and integrations.

app/app.vue
<script setup lang="ts">
import { defineFetchersContext, defineQueryClientContext } from '@ginjou/vue'
import { QueryClient } from '@tanstack/vue-query'

defineQueryClientContext(
    new QueryClient()
)
defineFetchersContext({
    default: {
        getList: async ({ resource }) => ({ data: [], total: 0 }),
        getOne: async ({ resource, id }) => ({ data: {} }),
    },
})
</script>

<template>
    <NuxtLayout>
        <NuxtPage />
    </NuxtLayout>
</template>

Async Composables

To fully support Server-Side Rendering (SSR), the module provides "Async" versions of standard composables

These composables share the same lifecycle benefits as Nuxt useAsyncData and serve as an extension of it for Ginjou's data model.

Common async composables include:

ComposableDescription
useAsyncGetOneFetches a single record from a data source.
useAsyncGetManyFetches multiple records from a data source.
useAsyncGetListFetches a list of records from a data source.
useAsyncGetInfiniteListFetches an infinite list of records from a data source.
useAsyncShowManages state and data for detail views.
useAsyncEditManages state and data for edit forms.
useAsyncListManages state and data for list views.
useAsyncInfiniteListManages state and data for infinite list views.
useAsyncSelectManages state and data for select views.
useAsyncAuthenticatedChecks the current authentication status.
useAsyncGetIdentityRetrieves the current user's identity.
useAsyncPermissionsRetrieves the current user's permissions.
useAsyncCanAccessChecks if the current user has access to a resource.

Example:

<script setup lang="ts">
// No import needed - auto-imported by Nuxt!
const { data, isLoading } = await useAsyncGetList({
    resource: 'posts'
})
</script>

<template>
    <div v-if="isLoading">
        Loading...
    </div>
    <ul v-else>
        <li v-for="post in data" :key="post.id">
            {{ post.title }}
        </li>
    </ul>
</template>