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?
- CORS avoidance — No cross-origin issues
- Cookie management — Auth cookies handled server-side
- Security — Backend URL never exposed to the client
- Header management — Auth headers stripped for auth endpoints
Key Pinia Stores
useAuthStore()
The main authentication store with actions:
| Action | Description |
|---|---|
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, enrollmentuseResourcesStore()— Resource listing, search, submissionuseToolsStore()— Tool listing, search, submissionuseChatStore()— AI chat sessions and history
Environment Variables Reference
| Variable | Runtime | Description |
|---|---|---|
DIRECTUS_URL | Server | Directus API base URL |
NUXT_PUBLIC_SITE_URL | Public | Site's public URL |
NUXT_PUBLIC_COMING_SOON_ENABLED | Public | Coming soon toggle |
NUXT_PUBLIC_INVITE_ROLE | Public | Directus role for invitees |
NUXT_PUBLIC_AVATAR_UPLOAD_FOLDER | Public | Avatar folder ID |
NUXT_PUBLIC_RESOURCE_UPLOAD_FOLDER | Public | Resource folder ID |
NUXT_PUBLIC_TOOL_UPLOAD_FOLDER | Public | Tool folder ID |
Variables prefixed with
NUXT_PUBLIC_are exposed to the client-side bundle.