vuejs-jwt

Lightweight JWT library for Vue.js 2
26,880 28
Install
npm install vuejs-jwt
Latest Version:1.1.0
Vue:2
License:ISC
Last Updated:Apr 2, 2018
Links: GitHub  ·  npm
Maintainer: renoguyon

vuejs-jwt

Lightweight JWT handler for Vue.js 2.

Getting Started

Install using npm:

$ npm install vuejs-jwt --save

Import and register Vue plugin:

import Vue from 'vue'
import VueJWT from 'vuejs-jwt'

Vue.use(VueJWT, options)

Available options are described below.

Usage

In your Vue.js components, simply call one of these methods:

// Return true / false - check if a JWT token is stored in cookies or local storage
this.$jwt.hasToken()

// Return token from cookies or local storage
this.$jwt.getToken()

// Decode JWT token and return payload
this.$jwt.decode()

You can also specify a custom token and sign key:

this.$jwt.decode(customToken, secretKey)

$jwt object is also available outside of components using Vue object:

import Vue from 'vue'

const payload = Vue.$jwt.decode()

Available options

signKey (required) : Token signature key

storage (default: localStorage) : cookie | localStorage

keyName (default: auth_token) : name of the key used to fetch token from cookie or local storage

ignoreExpiration (default: false) : set true to ignore expiration date

ignoreNotBefore (default: false) : set true to ignore 'not before' date

audience (default: null) : you can specify a string if you want to validate token audience property

issuer (default: null) : you can specify a string if you want to validate token issuer

subject (default: null) : you can specify a string if you want to validate token subject

Related Packages

vue-auth

Vue plugin for easily managing auth state

1,200 15
vue-easy-jwt

Library for decoding a jwt token

5,094 4
@musikhood-dev/auth-client

Auth client for browser apps. Cookies + automatic refresh + React and Vue 3 adap...

3,326 0
@aria-iam/vue

ARIA authentication Vue 3 adapter — AriaIamPlugin, useAuth, usePermissions and P...

1,167 1

Version History

Version Released License
1.1.0 ISC
1.0.0 ISC