You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
npm install --save brainless-token-manager@latest
or
yarn add brainless-token-manager
Introduction
This package help you do refresh token brainlessly
Flow
Checking refresh token -> expired -> onInvalidRefreshToken -> clear token on your storage -> logout
Valid token -> return token -> run as normal
Token in valid -> refresh token -> onRefreshToken success -> save token and refresh token to storage -> perform request
Super easy to use
API
// Works fine with JWT// if you use other tokens JWT. you need to initialize isValidToken and isValidRefreshTokeninterfaceTokenManagerContructor{getAccessToken: ()=>Promise<string>;getRefreshToken: ()=>Promise<string>;// if you don't have refresh token use the same as getAccessTokenexecuteRefreshToken?: ()=>Promise<{token: string;refresh_token: string}>;onRefreshTokenSuccess?: ({ token, refresh_token }: {token: string;refresh_token: string})=>void;onInvalidRefreshToken: ()=>void;// will trigger when refresh token expiredisValidToken?: (token: string)=>Promise<boolean>;isValidRefreshToken?: (refresh_token: string)=>Promise<boolean>;refreshTimeout?: number;}consttokenManagerInstance: TokenManager=newTokenManager(options: TokenManagerContructor);