1- import type { AxiosResponse , InternalAxiosRequestConfig } from 'axios' ;
2-
31import { useAuthStore } from '@/stores/AuthStore' ;
4- import { AxiosError } from 'axios' ;
52import { getCSRF } from '@/service/authAPI' ;
63import { toast } from '@aminnausin/cedar-ui' ;
74
5+ import axios , { AxiosError , type AxiosResponse , type InternalAxiosRequestConfig } from 'axios' ;
86import nProgress from 'nprogress' ;
9- import axios from 'axios' ;
107
118// For progress bar
129let progressTimeout : NodeJS . Timeout ;
@@ -17,11 +14,9 @@ let isRefreshing = false;
1714let queue : Array < ( tokenReady : boolean ) => void > = [ ] ; // A queue of promises that are conditionally called after attempt at refreshing csrf
1815
1916function refreshCsrf ( ) {
20- if ( ! csrfRefreshPromise ) {
21- csrfRefreshPromise = getCSRF ( ) . finally ( ( ) => {
22- csrfRefreshPromise = null ;
23- } ) ;
24- }
17+ csrfRefreshPromise ??= getCSRF ( ) . finally ( ( ) => {
18+ csrfRefreshPromise = null ;
19+ } ) ;
2520
2621 return csrfRefreshPromise ;
2722}
@@ -47,7 +42,7 @@ const handleError = async (error: AxiosError<{ message?: string }>) => {
4742
4843 const auth = useAuthStore ( ) ;
4944 const status = error . response ?. status ?? 0 ;
50- const config = error . config as InternalAxiosRequestConfig & { _retried ?: boolean } ;
45+ const config = error . config ;
5146 const message = error . response ?. data ?. message ?? error . message ;
5247 const showToast = ! config ?. headers ?. [ 'X-Skip-Toast' ] ;
5348
0 commit comments