Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

eezing/jwt-jot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwt-jot

A simple javascript JWT helper Object

  • For browsers: Integrated with localStorage for easy persisted token management

Build Status npm version

Browser Object

Import library

import { Browser as JotBrowser } from 'jwt-jot'

Create new instance

let key = 'id_token'
let token = myJWTFromSomewhere()

// * Option 1: with <key, token> arguments
// Will save token to window.localStorage at specified key
let jot = new JotBrowser(key, token)

// * Option 2: with <key> argument
// Will get token from localStorage if it exists
let jot = new JotBrowser(key)

Instance method - valid()

jot.valid() // --> bool

Instance method - getClaim()

let claimKey = 'role' // <-- specify property name in token payload

jot.getClaim(claimKey) // --> token payload['role'] or undefined

Instance method - getToken()

jot.getToken() // --> JWT or null

Instance method - eject()

jot.eject() // removes token from localStorage