1.0.9 • Published 7 years ago

jwt-xhr-hook v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

JWT XHR hook

Build Status Coverage Status

XHR hook to save JWT into localStorage and inject it to request. Suppose to work even in browser using <script> tag. Но это не точно.

Installation

yarn add jwt-xhr-hook

or npm i --save jwt-xhr-hook if you are still using npm

Usage

Simple import TokenHook using default export.

import TokenHook, { catchToken, injectToken } from 'jwt-xhr-hook';

import { loginUrl, usersUrl } from './actions/urls';

const hook = new TokenHook();

// catch token is default hook BTW
// hook.installHook(loginUrl);
hook.installHook(loginUrl, catchToken);
hook.installHook(usersUrl, injectToken);

JWT XHR hook contains 2 built-in callbacks

Own inject/catch callbacks

hook.installHook(loginUrl, (xhr, [options, token]) => {
	// do something
});

where xhr is a default XMLHttpRequest object

Contributing

PR's are welcome 👍

Credits

Maintained by Albert Fazullin. hex22a - that's also me.

Twitter: @hex22a