Skip to content

JWTManager

JWT Manager is tool for use interceptors for handling alive access token

Import

import JWTManager from '@empeek-rnd-ui/services/axios/JWTManager';

Parameters

Name Type Default Description
axiosInstance AxiosInstance instance of axios.create
options JWTManagerOptions Manager Options

JWTManagerOptions

Name Type Default Description
getAccessToken () => string get access token from you application
updateTokens () => Promise< string > get new access token when it was expired
onRefreshFail () => void not required handler when refresh token is fail
jwtRefreshType 'request', 'response' 'request' refresh interceptor type

Return

Returned instance of Manager (object)

Name Type Description
eject () => void handler to eject interceptors

Usage

const manager = JWTManager(axiosInstance, { getAccessToken, updateTokens });

Example

In this example you can see how access token is refreshing, in case if it is expired

access token lifetime - 10s

refresh token lifetime - 20s