0.1.5 • Published 1 year ago

fe-jwt-auth v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

fe-jwt-auth

FE jwt auth library

Install

$ npm i fe-jwt-auth --save

Usage

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

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.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago