Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const refreshAuthLogic = failedRequest => axios.post('https://www.example.com/au
return Promise.resolve();
});

// Instantiate the interceptor (you can chain it as it returns the axios instance)
// Instantiate the interceptor
createAuthRefreshInterceptor(axios, refreshAuthLogic);

// Make a call. If it returns a 401 error, the refreshAuthLogic will be run,
Expand Down
22,877 changes: 7,258 additions & 15,619 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"axios": ">= 0.18 < 0.19.0 || >= 0.19.1"
},
"devDependencies": {
"@types/jest": "^24.9.1",
"axios": "^0.21.1",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"@types/jest": "^27.0.1",
"axios": "^0.21.4",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^4.0.0",
"declaration-bundler-webpack-plugin": "^1.0.3",
"jest": "^25.5.4",
"terser-webpack-plugin": "^2.3.7",
"ts-jest": "^25.5.1",
"ts-loader": "^6.2.2",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
"jest": "^27.2.0",
"terser-webpack-plugin": "^5.2.4",
"ts-jest": "^27.0.5",
"ts-loader": "^9.2.5",
"typescript": "^4.4.3",
"webpack": "^5.53.0",
"webpack-cli": "^4.8.0"
},
"files": [
"dist/index.d.ts",
Expand Down
20 changes: 19 additions & 1 deletion src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosAuthRefreshCache } from "../model";
import { AxiosAuthRefreshCache, AxiosAuthRefreshRequestConfig } from '../model';
import axios, { AxiosRequestConfig, AxiosStatic } from 'axios';
import createAuthRefreshInterceptor, { AxiosAuthRefreshOptions } from "../index";
import {
Expand Down Expand Up @@ -249,6 +249,24 @@ describe('Requests interceptor', () => {
}
});

it('doesn\'t intercept skipped request', async () => {
try {
let refreshed = 0;
const instance = axios.create();
createRequestQueueInterceptor(instance, cache, {});
createRefreshCall({}, async () => {
await sleep(400);
++refreshed;
}, cache);
await instance.get('http://example.com')
.then(() => expect(refreshed).toBe(1));
await instance.get('http://example.com', <AxiosAuthRefreshRequestConfig>{ skipAuthRefresh: true })
.then(() => expect(refreshed).toBe(1));
} catch (e) {
expect(e).toBeFalsy();
}
});

it('cancels all requests when refreshing call failed', async () => {
try {
let passed = 0, caught = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createRequestQueueInterceptor(
cache: AxiosAuthRefreshCache,
options: AxiosAuthRefreshOptions,
): number {
if (typeof cache.requestQueueInterceptorId === undefined) {
if (typeof cache.requestQueueInterceptorId === 'undefined') {
cache.requestQueueInterceptorId = instance.interceptors.request.use((request: CustomAxiosRequestConfig) => {
if(request?.skipAuthRefresh)
return request
Expand Down
12 changes: 8 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

Expand All @@ -6,22 +7,25 @@ module.exports = {
entry: "./src/index.ts",
externals: [ 'axios' ],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.min.js',
library: 'axios-auth-refresh',
libraryTarget: 'umd',
library: {
name: 'axios-auth-refresh',
type: 'umd'
},
globalObject: 'this'
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
module: {
rules: [
{ test: /\.tsx?$/, exclude: "/node-modules/", loader: "ts-loader" }
{ test: /\.tsx?$/, loader: "ts-loader" }
]
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin({ sourceMap: false })],
minimizer: [new TerserPlugin()],
},
plugins: [
new CleanWebpackPlugin()
Expand Down