@privyid/nuxt-csrf

Module CSRF for NUXT
26,088 9
Install
npm install @privyid/nuxt-csrf
Latest Version:1.0.0
License:MIT
Last Updated:Jan 1, 2026
Links: GitHub  ·  npm
Maintainer: dipadipprv

nuxt-csrf

Module CSRF for NUXT

Installation

Install the module

# NPM
npm install --save @privyid/nuxt-csrf

# Yarn
yarn add @privyid/nuxt-csrf

include in nuxt.config.js

// nuxt.config.js
{
  modules: [
    // Simple usage
    '@privyid/nuxt-csrf',

    // With options
    ['@privyid/nuxt-csrf', { /* module options */ }]
  ]
}

Usage

Get Token

via Component
const token = this.$csrfToken()
via Context
const token = context.app.$csrfToken()

Integrating with Axios

If you using @nuxtjs/axios, this module must be registered before @nuxtjs/axios axios module.

// nuxt.config.js
{
  modules: [
    '@privyid/nuxt-csrf', // <-- must be placed before @nuxtjs/axios
    '@nuxtjs/axios',
  ]
}

Autosend CSRF Token

If you want axios automatically send CSRF Token in every request, you can add this into your axios's interceptors. If you not familiar with it before, goto this.

// ~/plugins/axios.js
export default function ({ $axios, app, redirect }) {
  $axios.onRequest(config => {
    const token = app.$csrfToken()

    if (!config.headers['X-CSRF-Token'] && token)
      config.headers['X-CSRF-Token'] = token

    return config
  })
}

License

Distributed under the MIT License. See LICENSE for more information.

Related Packages

nuxt-csurf

Nuxt Cross-Site Request Forgery (CSRF) Prevention

6,263,746 91
mixpanel-nuxt

Mixpanel module for Nuxt

19,992 7
nuxt-radash

radash for Nuxt

10,601 20
gsap-nuxt-module

GSAP integration for Nuxt.

8,932 37
@docus/core-edge

The Docus core.

8,638

Version History

Version Released License
1.0.0 MIT