JWT XHR hook
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