24
Reference

Auth and Request Hooks

Inject auth headers and context before every FormForge request.

Use the Nuxt hook formforge:beforeRequest to inject auth and contextual headers.

plugins/formforge-auth.client.ts
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.hook('formforge:beforeRequest', ({ headers }) => {
    const token = useCookie<string | null>('auth_token')

    if (typeof token.value === 'string' && token.value !== '') {
      headers.Authorization = `Bearer ${token.value}`
    }
  })
})

With Sanctum or cookie-based auth, keep:

  • credentials: 'include'