Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@wavesenterprise/api-token-refresher
Advanced tools
Wavesenterprise JWT refresh library for both Node.js and browser.
Wavesenterprise JWT refresh library for both Node.js and browser.
npm install @wavesenterprise/api-token-refresher --save
type TokenPair = {
access_token: string,
refresh_token: string,
}
export type TokenRefresherConfig = {
authorization: TokenPair, // inital auth pair
refreshCallback(refreshToken: string): Promise<TokenPair>, // called to get new TokenPair
axiosRequestConfig?: AxiosRequestConfig, // optional, custom AxiosRequestConfig
onChangeAccessToken?(token: string): void, // optional, called after success token refresh
onRefreshFailed?(err: any): void, // optional, default console.log(err), called in case refresh error
refreshBeforeExpire?: number, // optional, default 30000, refresh will start if expiration - refreshBeforeExpire < Date.now()
minTimeBeforeExpireToSendReq?: number, // optional, default 1000, if expiration - minTimeBeforeExpireToSendReq < Date.now() token will be updted synchronously before req
maxAttemptsToRefreshToken?: number, // optional, default 5
sleepAfterError?: number, // optional default 1000
}
Full example can be found in examples/
folder
import { ApiTokenRefresher } from '@wavesenterprise/api-token-refresher'
import axios from 'axios'
const refreshCallback = async (token: string) => {
return Promise.reject('just test')
try {
const { data } = await axios.post(`${AUTH_SERVICE_ADDRESS}/v1/auth/refresh`, { token })
console.log('token refreshed')
return data
} catch (e) {
console.log('refresh failed relogin')
return getTokens()
}
}
const apiTokenRefresher = new ApiTokenRefresher({
authorization: tokens,
refreshCallback,
})
const { axios, fetch } = apiTokenRefresher.init()
import { init } from 'vostok-auth-refresh/axios';
const axios = init({
authorization: {
access_token: "",
refresh_token: ""
},
async refreshCallback(token: string): Promise<ITokenPair> {
return api.getRefreshToken(token)
},
onChangeAccessToken(token: string): void {
// do smth with new access token
},
});
changed to
import { ApiTokenRefresher } from '@wavesenterprise/api-token-refresher'
const apiTokenRefresher = new ApiTokenRefresher({
authorization: {
access_token: "",
refresh_token: ""
},
async refreshCallback(token: string): Promise<ITokenPair> {
return api.getRefreshToken(token)
},
onChangeAccessToken(token: string): void {
// do smth with new access token
},
)
const { axios } = apiTokenRefresher.init();
FAQs
Unknown package
The npm package @wavesenterprise/api-token-refresher receives a total of 1 weekly downloads. As such, @wavesenterprise/api-token-refresher popularity was classified as not popular.
We found that @wavesenterprise/api-token-refresher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.