https://github.com/hex22a/jwt-xhr-hook
Hook to inject JWT to XHR
https://github.com/hex22a/jwt-xhr-hook
Last synced: 5 months ago
JSON representation
Hook to inject JWT to XHR
- Host: GitHub
- URL: https://github.com/hex22a/jwt-xhr-hook
- Owner: hex22a
- License: mit
- Created: 2017-05-12T04:46:00.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-29T03:46:12.000Z (about 9 years ago)
- Last Synced: 2025-10-09T05:29:31.311Z (9 months ago)
- Language: JavaScript
- Size: 108 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWT XHR hook
[](https://travis-ci.org/hex22a/jwt-xhr-hook)
[](https://coveralls.io/github/hex22a/jwt-xhr-hook?branch=master)
XHR hook to save JWT into localStorage and inject it to request. Suppose to work even in browser using `` 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.
```javascript
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](src/hooks.js)
## Own inject/catch callbacks
```javascript
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](http://github.com/AlbertFazullin).
[hex22a](http://github.com/hex22a) - that's also me.
Twitter: [@hex22a](https://twitter.com/hex22a)