React JWT user store
const userStore = require('react-jwt-store')()
userStore.on('Token received', (token, user) => {
console.log(token, user)
})
userStore.init()In order to trigger the store's refresh mechanism and send data to any event
handlers, you must call the init method.
userStore.init()You can set the token without interacting with cookies via the following.
userStore.setToken('jwt')You can force a refresh of the token via the following.
userStore.refreshToken()By default, the JWT assumes the cookie key is XSRF-TOKEN. This can be overridden
by passing cookie on the options hash:
let userStore = require('react-jwt-store')({ cookie: 'NOT-XSRF-TOKEN'});By default, the store does not log anything, but if you pass in a console
compatible logger, the store will log the state of the token as it changes.
By default, if you set token to null:
userStore.setToken(null)...an interval responsible for refreshing tokens (the one set up on init) will not be cleared. If you want to clear it explicitly, then you can do it with:
userStore.terminate()