Module Configuration

Configure component prefix, theme colors, fonts, API endpoints, auth strategy, response parsing rules and Toast notification behavior.
View source

Introduction

Movk Nuxt uses movk as the configuration key in nuxt.config.ts:

Prefix

  • Type: string
  • Default: 'M'

Component prefix, used to avoid naming conflicts with other component libraries.

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    prefix: 'My' // Components become MyAutoForm, MyDatePicker, etc.
  }
})

Theme

The theme module centrally manages colors, radius, icon sets and fonts. The first three provide options to the ThemePicker component and useTheme composable, while the font is injected at build time. All fields are configured under movk.theme.

Runtime capabilities of the theme system (dynamic switching, CSS export) are documented in the theme docs; for interactive tuning see the ThemePicker component.
nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    theme: {
      enabled: true
    }
  }
})
enabled
boolean
Whether to enable the theme module (appConfig defaults, theme plugin, ThemePicker component registration). Defaults to true. When disabled, ThemePicker is no longer registered.
colors
string[]
List of color aliases available to components, passed through to @nuxt/ui's theme.colors. Defaults to ['primary', 'secondary', 'success', 'info', 'warning', 'error'].
defaultVariants
object
Component default variants, passed through to @nuxt/ui's theme.defaultVariants.
prefix
string
Tailwind CSS utility class prefix, passed through to @nuxt/ui's theme.prefix. For example 'tw'.
font
string | ThemeFontOption
Global font. For built-in fonts the name is enough ('Alibaba PuHuiTi', 'OPPO Sans') and the module injects the stylesheet, a preconnect and a --font-sans carrying the Chinese fallback stack at build time; for self-hosted fonts use the { name, href } form to supply the stylesheet URL. When omitted, --font-sans is not injected and the font is controlled entirely by your project's CSS @theme.
radius
number
Default radius (in rem). When omitted, --ui-radius is not injected and the @nuxt/ui default or your project CSS applies. For example 0.5.
radiuses
number[]
ThemePicker radius options (in rem). Defaults to [0, 0.125, 0.25, 0.375, 0.5].
neutralColors
string[]
ThemePicker neutral color options.

Custom Font

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    theme: {
      // Built-in fonts only need the name
      font: 'Alibaba PuHuiTi'
      // Self-hosted fonts supply the entry CSS URL
      // font: { name: 'My Font', href: '/fonts/my-font.css' }
    }
  }
})

Icon

Controls whether the module's own icons enter the @nuxt/icon build-time bundle.

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    icon: {
      clientBundle: true
    }
  }
})
clientBundle
boolean
Whether to inject the icons used by movk components and the built-in icon sets into the build-time bundle. Defaults to true. When disabled, those icons are fetched on demand at runtime.
See Theme · Icon Sets for switching icon sets and installing the @iconify-json/* packages.

API

The API system provides complete request wrapping and auth management, configured via the api option.

See the API docs for full usage of the API system.

Basic Configuration

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      // Whether to enable API functionality
      enabled: true,
      // Default endpoint name
      defaultEndpoint: 'default',
      // Whether to enable debug mode
      debug: false
    }
  }
})
enabled
boolean
Whether to enable API functionality. Defaults to true.
defaultEndpoint
string
Default endpoint name. Defaults to 'default'.
debug
boolean
Whether to enable debug mode; when enabled, request logs are printed to the console. Defaults to false.

endpoints

Supports configuring multiple API endpoints, each with its own independent configuration:

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      endpoints: {
        // Default endpoint
        default: {
          baseURL: '/api'
        },
        // Admin endpoint
        admin: {
          baseURL: '/admin-api',
          auth: {
            tokenType: 'Bearer'
          }
        },
        // Third-party API
        external: {
          baseURL: 'https://api.example.com',
          // Injected on the server only
          headers: {
            'X-Secret-Key': process.env.EXTERNAL_SECRET_KEY
          },
          // Injected on both server and client
          publicHeaders: {
            'X-Api-Version': '2'
          }
        }
      }
    }
  }
})

Endpoint Options

baseURL
string required
Base URL of the endpoint.
alias
string
Endpoint alias.
headers
Record<string, string>
Default request headers for this endpoint. Server-side only; not exposed to the client.
publicHeaders
Record<string, string>
Public request headers for this endpoint. Stored in the public runtimeConfig and injected on both server and client. Keys of the same name are overridden by headers. Use for non-secret constant headers only.
auth
Partial<ApiAuthConfig>
Auth configuration for this endpoint, merged with the global config.
toast
Partial<ApiToastConfig>
Toast configuration for this endpoint, merged with the global config.
response
Partial<ApiResponseConfig>
Response configuration for this endpoint, merged with the global config.

auth

Configure automatic auth behavior, integrated with nuxt-auth-utils:

The module automatically registers nuxt-auth-utils when auth.enabled is true and tokenSource is 'session'. To use useUserSession on its own, add nuxt-auth-utils to modules.With nuxt-auth-utils v0.6, set NUXT_APP_SECRET to a value of at least 32 characters in production. Generate one with openssl rand -base64 32. In development, Nuxt generates a secret if the variable is unset.When upgrading from v0.5, remove NUXT_SESSION_PASSWORD and runtimeConfig.session.password. Signed-in users will need to sign in again once after the upgrade. Migration guide
nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      auth: {
        // Enable auth
        enabled: true,
        // Token source
        tokenSource: 'session',
        // Path to token in session
        sessionTokenPath: 'user.accessToken',
        // Token type
        tokenType: 'Bearer',
        // Header name
        headerName: 'Authorization',
        // 401 unauthorized handling config
        unauthorized: {
          // Redirect to login page on 401
          redirect: true,
          loginPath: '/login',
          // Clear session on 401
          clearSession: true
        }
      }
    }
  }
})

When calling a third-party API directly from the browser, put the credential in runtimeConfig.public and point at it:

nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      llmApiKey: ''
    }
  },
  movk: {
    api: {
      auth: {
        enabled: true,
        tokenSource: 'public-runtime-config',
        tokenPath: 'llmApiKey',
        tokenType: 'Bearer',
        unauthorized: {
          redirect: false
        }
      }
    }
  }
})
.env
NUXT_PUBLIC_LLM_API_KEY=your-api-key
Values from public-runtime-config and publicHeaders are shipped to the browser along with the page, and any visitor can read them. Use them only when the credential is designed to be public, or its scope is narrow enough to accept the exposure. Account-level keys belong behind a server-side proxy.

Auth Options

enabled
boolean
Whether to enable auth. Defaults to false.
tokenSource
'session' | 'public-runtime-config'
Token source. 'session' retrieves it from the nuxt-auth-utils session; 'public-runtime-config' retrieves it from runtimeConfig.public, for credentials that are meant to be exposed in the browser. Defaults to 'session'.
sessionTokenPath
string
Path to the token in the session. For example 'token' maps to session.token, 'user.token' maps to session.user.token. Defaults to 'token'.
tokenPath
string
Path to the token in runtimeConfig.public, dot-notation supported. Only applies when tokenSource is 'public-runtime-config'. Defaults to 'apiToken'.
tokenType
'Bearer' | 'Basic' | 'Custom'
Token type. Defaults to 'Bearer'.
customTokenType
string
Custom token type value, used when tokenType is 'Custom'.
headerName
string
Header name. Defaults to 'Authorization'.
unauthorized
ApiUnauthorizedConfig
Configuration for handling 401 unauthorized errors.

response

Configure API response parsing rules, including business status code determination, data unwrapping fields and message extraction:

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      response: {
        // Successful status code list
        successCodes: [200, 0],
        // Status code field name
        codeKey: 'code',
        // Message field name
        messageKey: 'message',
        // Data field name
        dataKey: 'data',
        // Whether to validate the business status code
        businessCheck: true,
        // Whether to unwrap by dataKey
        unwrap: true
      }
    }
  }
})

An endpoint-level response overrides the global one. Endpoints returning a bare array or object turn off checking and unwrapping; explicit per-request businessCheck / unwrap values can still override:

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      endpoints: {
        sensor: {
          baseURL: 'https://sensor.example.com',
          response: { businessCheck: false, unwrap: false }
        }
      }
    }
  }
})

Response Configuration Options

successCodes
(number | string)[]
Successful status code list; a code value in the response is considered successful if it is in this list. Defaults to [200, 0].
codeKey
string
Field name for the status code in the response. Defaults to 'code'.
messageKey
string
Field name for the message in the response. Defaults to 'message'.
dataKey
string
Field name for the data in the response. Defaults to 'data'.
businessCheck
boolean
Whether to validate the business status code against successCodes; when off, any 2xx response is a success. Defaults to true.
unwrap
boolean
Whether to unwrap business data by dataKey; when off, callers receive the raw response body. Defaults to true.

toast

Configure global Toast notification behavior:

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      toast: {
        // Enable notifications globally
        enabled: true,
        // Success notification config
        success: {
          show: true,
          color: 'success',
          duration: 3000,
          // Only notify on mutating requests, stay quiet on GET
          methods: ['POST', 'PUT', 'PATCH', 'DELETE']
        },
        // Error notification config
        error: {
          show: true,
          color: 'error',
          duration: 3000
        }
      }
    }
  }
})

Toast Options

enabled
boolean
Whether to enable notifications globally. Defaults to true.
success
Partial<Toast> & { show?: boolean, methods?: string[] }
Success notification configuration. show: false disables it; methods restricts it to the listed HTTP methods (case-insensitive), and omitting the field means no restriction.
error
Partial<Toast> & { show?: boolean, methods?: string[] }
Error notification configuration. show: false disables it; methods works the same way, and is usually left unset so errors surface on every method.
enabled, show and methods are all global-level switches that a single request can override. Precedence: request-level show > request-level successMessage / errorMessage > global success.show / error.show / methods > global enabled. So when a toast is globally disabled or the method misses the whitelist, both toast: { success: { show: true } } and toast: { successMessage: 'Saved' } still show it.
methods only belongs in the global or endpoint config — a single request has exactly one method, so request-level toast does not accept the field. An endpoint-level methods replaces the global one instead of merging the arrays.

Configuration Priority

Configuration is merged in the following priority order (later overrides earlier):

  1. Module built-in defaults - Default config defined in api-defaults.ts
  2. Global config - movk.api.auth, movk.api.toast, movk.api.response
  3. Endpoint config - movk.api.endpoints[name].auth, etc.
  4. Request-level config - toast option in useApiFetch, etc.
// Example: request-level config overrides global config
const { data } = await useApiFetch('/users', {
  toast: {
    successMessage: 'Fetched successfully', // Overrides global config
    error: false // Disable error notifications
  }
})

Request headers are layered in the following order (later overrides earlier):

  1. Endpoint publicHeaders - Injected on both server and client
  2. Endpoint headers - Injected on the server only, overrides matching publicHeaders keys
  3. Request-level headers - Passed to $api or useApiFetch
  4. Auth injection - Written by the onRequest interceptor under headerName, highest priority

Component and Validation Locale

Set the locale on UApp to change component text. Use extendMovkLocale(locale, overrides) to override individual messages and useMovkLocale() to read the active locale code and translator.

nuxt.config.ts
export default defineNuxtConfig({
  movk: { zod: { locale: 'auto', fallback: 'en', locales: ['en', 'zh-CN'] } }
})

movk.zod configures the global validation locale and required messages. With auto, AutoForm and SearchForm follow UApp on the client and use fallback on the server. Set customError through movk:zod:config to customize those forms in the current Nuxt application. In Vue + Vite pass { zod: { customError } } to the Vue plugin. Direct Zod validation uses the configured global locale or fallback.

Environment Variables

For sensitive configuration (such as API keys), use environment variables:

nuxt.config.ts
export default defineNuxtConfig({
  movk: {
    api: {
      endpoints: {
        external: {
          baseURL: process.env.EXTERNAL_API_URL,
          headers: {
            'X-API-Key': process.env.EXTERNAL_API_KEY
          }
        }
      }
    }
  }
})
.env
EXTERNAL_API_URL=https://api.example.com
EXTERNAL_API_KEY=your-api-key
Never write sensitive information (such as API keys or passwords) directly in configuration files; always use environment variables.
Copyright © 2025 - 2026 YiXuan - MIT License