Configuration

Module nuxt-beditacan be customized throught the bedita property of nuxt.config.

Simple nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@atlasconsulting/nuxt-bedita',
  ],
  bedita: {
    apiBaseUrl: 'http://bedita-api.localhost',
    apiKey: '1a2bc3d4',
    session: {
      name: 'nuxt-bedita',
      secret: '<at-least-32-chars-secret-string>',
    },
  },
})
Complete nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@atlasconsulting/nuxt-bedita',
  ],
  bedita: {
    apiBaseUrl: 'http://bedita-api.localhost',
    apiKey: '1a2bc3d4',
    auth: {
      global: true,
      required: false,
      publicRoutes: [],
      unauthenticatedRedirect: '/sign-in',
      rolesGuard: {},
      sessionUserProps: [],
    },
    endpoints: ['auth'],
    projects: {
      one: {
        apiBaseUrl: 'http://bedita-api-one.localhost',
        apiKey: 's9suff64h',
      },
      two: {
        apiBaseUrl: 'http://bedita-api-two.localhost',
        apiKey: 'plog8uhcft',
      },
    },
    proxyEndpoints: [
      {
        path: '*',
        methods: ['GET'],
      }
    ],
    recaptcha: {
      enabled: true,
      siteKey: 'recaptcha-v3-site-key',
      secretKey: 'recaptcha-v3-secret-key',
      hideBadge: false,
      useRecaptchaNet: true,
    },
    replaceTranslations: true,
    resetPasswordPath: '/reset-password',
    session: {
      name: 'nuxt-bedita',
      secret: '<at-least-32-chars-secret-string>',
    },
  },
})
You can also take advantage of env variables prefixed with NUXT_ to configure some module properties by environment instead of edit the bedita property.

apiBaseUrl required

The BEdita API base URL.

TypeDefaultOptionsEnv
string--NUXT_BEDITA_API_BASE_URL

apiKey required

The BEdita API key.

TypeDefaultOptionsEnv
string--NUXT_BEDITA_API_KEY

auth

Configure user auth stuff as the auth middleware that is responsible for fill the user state reading from session and to protect routes too.

Type Default Options Env
Object
auth: {
  global: true,
  required: false,
  publicRoutes: [],
  unauthenticatedRedirect: '/sign-in',
  rolesGuard: {},
  sessionUserProps: [],
},
        
  • global: if auth middleware has to be installed as global middleware [default true]
  • required: if authentication is required in the entire app [default false].
    If it is true an user unauthenticated will be redirect to the route specified in unauthenticatedRedirect property.
  • publicRoutes: list of public routes not affected by authentication check [default []]
  • unauthenticatedRedirect: a route to redirect unauthenticated users [default /sign-in]
  • rolesGuard: role based route rules to forbid access to some routes for users that don't have some BEdita roles [default {}]
  • sessionUserProps: additional user properties (beyond id, name, surname, username, email, roles) saved in session when authentication happens. They are available getting user from useBeditaAuth composable [default []]
-

endpoints

List of internal API endpoints' groups enabled.

Two endpoints' groups are available:

  • auth enable all endpoints related to user autentication
    • POST /api/bedita/auth user authenitcation
    • /api/bedita/auth/logout user logout
    • POST /api/bedita/auth/reset request of password reset
    • PATCH /api/bedita/auth/change change password
    • POST /api/bedita/auth/optout user opt-out
  • signup enable all endpoints related to signup flow
    • POST /api/bedita/signup user signup
    • POST /api/bedita/signup/activation user signup activation
TypeDefaultOptionsEnv
Array['auth', 'signup']auth, signup-

projects

Used to setup different API configuration. For example:

nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@atlasconsulting/nuxt-bedita',
  ],
  bedita: {
    projects: {
      one: {
        apiBaseUrl: 'http://bedita-api-one.localhost',
        apiKey: 's9suff64h',
      },
      two: {
        apiBaseUrl: 'http://bedita-api-two.localhost',
        apiKey: 'plog8uhcft',
      },
    },
  },
})

In the app you can call a special endpoint /api/bedita/_project to set the project to use.

await $fetch('/api/bedita/_project', {
  method: 'POST',
  body: { project: 'two'},
})

Once setup project every call to BEdita API will use the project two configuration.

Type Default Options Env
Object projects: Record <string, BeditaProjectConf> - NUXT_BEDITA_PROJECTS

proxyEndpoints

Use this property to enable/disable API proxy to BEdita API. It is configurable per endpoint.

By default all GET requests are proxied to BEdita API (if not found in routing context), for example a request in the app to /api/bedita/documents will be proxied to GET /documents BEdita API.

It is possible to limit the requests proxied defining the endpoints allowed. For example the following configuration enable GET /api/bedita/events and GET /api/bedita/news while other GET /api/bedita/<other-bedita-endpoint> request will return a 404 Not Found.

nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@atlasconsulting/nuxt-bedita',
  ],
  bedita: {
    proxyEndpoints: [
      {
        path: '/events',
        methods: ['GET'],
      },
      {
        path: '/news',
        methods: ['GET'],
      }
    ],
  },
})
Type Default Options Env
Array
proxyEndpoints: [
  {
    path: '*', // all endpoints allowed
    methods: ['GET'], // HTTP methods allowed
  },
]
        
- -

recaptcha

reCAPTCHA v3 can be enabled to protect login, signup and other actions that require it. By default it is disabled.

Type Default Options Env
Object
recaptcha: {
  enabled: false,
  hideBadge: false,
  useRecaptchaNet: false,
},
        
  • enabled: enable/disable reCAPTCHA [default false]
  • siteKey: the reCAPTCHA site key
  • secretKey: the reCAPTCHA secret key
  • hideBadge: enable/disable reCAPTCHA badge [default false]
  • useRecaptchaNet: enable/disable the use of recaptcha.net domain instead of google.com [default false]
  • NUXT_PUBLIC_RECAPTCHA_ENABLED
  • NUXT_PUBLIC_RECAPTCHA_SITE_KEY
  • NUXT_BEDITA_RECAPTCHA_SECRET_KEY
  • NUXT_PUBLIC_RECAPTCHA_HIDE_BADGE
  • NUXT_PUBLIC_RECAPTCHA_USE_RECAPTCHA_NET

replaceTranslations

Configure BEdita client to replace in the API response the main language attributes of BEdita objects with translated fields requested via lang query string.

With this option enabled you can always refer to main objects attributes to get the requested translation.

Example:

GET /api/bedita/documents

will returns documents with attributes in the main language.

GET /api/bedita/documents?lang=it

will returns documents with attributes in the Italian language, if exists.

TypeDefaultOptionsEnv
booleanfalse--

session required

Contain session configuration as the session name and session secret used to encrypt session. The session take advantage of unjs/h3 sessions storing values in a cookie sealed with the session secret.

Type Default Options Env
Object
session: {
  name: 'bedita',
  secret: '',
},
        
  • name: session name corresponding to session cookie [default bedita]
  • secret: session secret (at least 32 chars) used to encrypt session in cookie
  • NUXT_BEDITA_SESSION_NAME
  • NUXT_BEDITA_SESSION_SECRET