# jwt-xhr-hook

> XHR hook to save JWT into localStorage and inject it to request

Latest version **1.0.9** (published 2017-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install jwt-xhr-hook
pnpm add jwt-xhr-hook
yarn add jwt-xhr-hook
bun add jwt-xhr-hook
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2017-05-29 |
| First published | 2017-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | hex22a |
| Maintainers | hex22a |

## Links

- npm: https://www.npmjs.com/package/jwt-xhr-hook
- Repository: https://github.com/hex22a/jwt-xhr-hook
- Homepage: https://github.com/hex22a/jwt-xhr-hook#readme
- Issues: https://github.com/hex22a/jwt-xhr-hook/issues
- npm.io page: https://npm.io/package/jwt-xhr-hook

## Recent versions

- 1.0.9 (latest) — 2017-05-29
- 1.0.8 — 2017-05-29
- 1.0.7 — 2017-05-21
- 1.0.5 — 2017-05-12

## README

# JWT XHR hook
[![Build Status](https://travis-ci.org/hex22a/jwt-xhr-hook.svg?branch=master)](https://travis-ci.org/hex22a/jwt-xhr-hook)
[![Coverage Status](https://coveralls.io/repos/github/hex22a/jwt-xhr-hook/badge.svg?branch=master)](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 `<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.

```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)

---
_Source: https://npm.io/package/jwt-xhr-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
