0.1.4 • Published 2 months ago

fe-jwt-auth v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

fe-jwt-auth

FE jwt auth library

Install

$ npm i fe-jwt-auth --save

Usage

import {initService, axiosInstance} 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')

Options

KeyDefaultDefinition
requestOptions{headers: {'Content-Type': 'application/json',},responseType: 'json'}AxiosRequestConfig
refreshTokenTimeBufferInSecond0Time buffer in second.
localStorageAuthServicelocalStorageAuthServiceDefaultILocalStorageAuthService
headersCustom request header.
eventsHandle on logout or forbidden
refreshTokenRoute/auth/refresh-tokenUrl path to refresh token
accessTokenKeyaccessToken.tokenkey to get access token
refreshTokenKeyrefreshToken.tokenkey to get refresh token
expiredTimeKeyexpiredTimekey from JWT

ILocalStorageAuthService

KeyDefinition
getAccessToken() => string
setAccessToken(token: string) => void;
getRefreshToken() => string;
setRefreshToken(token: string) => void;
resetAll() => void;
0.1.4

2 months ago

0.1.3

2 months ago

0.1.2

2 months ago

0.1.1

2 months ago

0.1.0

2 months ago