# fe-jwt-auth

> FE jwt auth library

Latest version **0.1.5** (published 2024-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install fe-jwt-auth
pnpm add fe-jwt-auth
yarn add fe-jwt-auth
bun add fe-jwt-auth
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2024-05-23 |
| First published | 2024-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 204.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ttlab_npm |
| Keywords | ice, web, library |

## Links

- npm: https://www.npmjs.com/package/fe-jwt-auth
- npm.io page: https://npm.io/package/fe-jwt-auth

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) ^1.6.8
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^4.0.0
- [@swc/helpers](https://npm.io/package/@swc/helpers.md) ^0.5.1
- [@ice/jsx-runtime](https://npm.io/package/@ice/jsx-runtime.md) ^0.2.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2024-05-23
- 0.1.4 — 2024-04-04
- 0.1.3 — 2024-04-04
- 0.1.2 — 2024-04-04
- 0.1.1 — 2024-04-04
- 0.1.0 — 2024-04-04

## README

# fe-jwt-auth

FE jwt auth library

## Install

```bash
$ npm i fe-jwt-auth --save
```

## Usage

```js
import {initService, axiosInstance, ApiService} from 'fe-jwt-auth';

initService({
    headers: {
        'x-timezone': '+07',
    },
    requestOptions: {
        baseUrl: 'http://localhost:3000/api'
    },
    events: {
        onLogout: () => {
            // handle logout
        },
        onForbidden: () => {
            // handle forbidden
        }
    }
})

// call api
const uses = await axiosInstance.get('/users')

// use ApiService
const userService = new ApiService({ baseUrl: '/user' }, axiosInstance)
const userList = userService.list()
```

## Options

| Key  |  Default   |  Definition   |
| -------- | ----------  | ----------  |
| requestOptions | {headers: {'Content-Type': 'application/json',},responseType: 'json'} | AxiosRequestConfig |
| refreshTokenTimeBufferInSecond | 0 | Time buffer in second. |
| localStorageAuthService | localStorageAuthServiceDefault | ILocalStorageAuthService |
| headers |  | Custom request header. |
| events |  | Handle on logout or forbidden  |
| refreshTokenRoute | /auth/refresh-token | Url path to refresh token |
| accessTokenKey | accessToken.token | key to get access token |
| refreshTokenKey | refreshToken.token | key to get refresh token |
| expiredTimeKey | expiredTime | key from JWT |

### ILocalStorageAuthService

| Key  |  Definition   |
| -------- | ----------  |
| getAccessToken | () => string |
| setAccessToken | (token: string) => void; |
| getRefreshToken | () => string; |
| setRefreshToken | (token: string) => void; |
| resetAll | () => void; |

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