Welcome to
Skip to main content
Home/Documentation/API Reference

API Reference

Directus integration, server proxy, and API patterns

Directus Integration

Hub Digital uses Directus as its headless CMS backend. All API communication goes through the Directus SDK.

Custom Directus Module

The custom Nuxt module at modules/directus/ provides:

  • Auto-configured Directus client via useNuxtApp().$directus
  • Authentication plugins for login/logout/session management
  • Auto-imported composables for data fetching
  • Runtime config injection for API URLs

Configuration

The Directus module is configured in nuxt.config.ts:

directus: {
  rest: {
    baseUrl: process.env.DIRECTUS_URL,
    nuxtBaseUrl: process.env.NUXT_PUBLIC_SITE_URL,
  },
  auth: {
    enabled: true,
    enableGlobalAuthMiddleware: false,
    userFields: ['id', 'first_name', 'last_name', ...],
    redirect: {
      login: '/auth/login',
      logout: '/',
      home: '/dashboard',
      resetPassword: '/auth/reset-password',
      callback: '/auth/callback',
      emailVerification: '/auth/verify-email',
    },
  },
}

Server-Side Proxy

All API requests are routed through a Nitro server handler at server/api/proxy/[...].ts.

How It Works

Client Request → /api/proxy/items/courses
  → Nitro Handler
    → Strips host/connection/cookie headers
    → Forwards to DIRECTUS_URL/items/courses
    → Returns response with set-cookie headers

Why a Proxy?

  1. CORS avoidance — No cross-origin issues
  2. Cookie management — Auth cookies handled server-side
  3. Security — Backend URL never exposed to the client
  4. Header management — Auth headers stripped for auth endpoints

Key Pinia Stores

useAuthStore()

The main authentication store with actions:

ActionDescription
login(email, password)Email/password authentication
logout()End session and redirect
register(email, password, first_name, last_name)User registration
fetchUser()Fetch current user data
updateUser(data)Update user profile
updateUserAvatar(file)Upload/update avatar
changePassword(current, new)Change password
inviteFriend(email)Send invitation
acceptInvite(token, password)Accept invitation

Data Stores

  • useCoursesStore() — Course listing, search, enrollment
  • useResourcesStore() — Resource listing, search, submission
  • useToolsStore() — Tool listing, search, submission
  • useChatStore() — AI chat sessions and history

Environment Variables Reference

VariableRuntimeDescription
DIRECTUS_URLServerDirectus API base URL
NUXT_PUBLIC_SITE_URLPublicSite's public URL
NUXT_PUBLIC_COMING_SOON_ENABLEDPublicComing soon toggle
NUXT_PUBLIC_INVITE_ROLEPublicDirectus role for invitees
NUXT_PUBLIC_AVATAR_UPLOAD_FOLDERPublicAvatar folder ID
NUXT_PUBLIC_RESOURCE_UPLOAD_FOLDERPublicResource folder ID
NUXT_PUBLIC_TOOL_UPLOAD_FOLDERPublicTool folder ID

Variables prefixed with NUXT_PUBLIC_ are exposed to the client-side bundle.