removed old beta
This commit is contained in:
@@ -13,7 +13,10 @@ let failedQueue: Array<{
|
||||
config: AxiosRequestConfig;
|
||||
}> = [];
|
||||
|
||||
const processQueue = (error: AxiosError | null, token: string | null = null) => {
|
||||
const processQueue = (
|
||||
error: AxiosError | null,
|
||||
token: string | null = null
|
||||
) => {
|
||||
failedQueue.forEach((prom) => {
|
||||
if (error) {
|
||||
prom.reject(error);
|
||||
@@ -52,13 +55,13 @@ export const resetCSRFToken = () => {
|
||||
// Check if authentication cookie exists
|
||||
export const hasAuthCookie = (): boolean => {
|
||||
return document.cookie
|
||||
.split('; ')
|
||||
.some(cookie => cookie.startsWith('accessToken='));
|
||||
.split("; ")
|
||||
.some((cookie) => cookie.startsWith("accessToken="));
|
||||
};
|
||||
|
||||
// Check if user has any auth indicators
|
||||
export const hasAuthIndicators = (): boolean => {
|
||||
return hasAuthCookie() || !!localStorage.getItem('token');
|
||||
return hasAuthCookie();
|
||||
};
|
||||
|
||||
api.interceptors.request.use(async (config) => {
|
||||
@@ -68,7 +71,9 @@ api.interceptors.request.use(async (config) => {
|
||||
// If we don't have a CSRF token yet, try to fetch it
|
||||
if (!csrfToken) {
|
||||
// Skip fetching for auth endpoints to avoid circular dependency
|
||||
const isAuthEndpoint = config.url?.includes("/auth/") && !config.url?.includes("/auth/refresh");
|
||||
const isAuthEndpoint =
|
||||
config.url?.includes("/auth/") &&
|
||||
!config.url?.includes("/auth/refresh");
|
||||
if (!isAuthEndpoint) {
|
||||
await fetchCSRFToken();
|
||||
}
|
||||
@@ -85,12 +90,18 @@ api.interceptors.request.use(async (config) => {
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
const originalRequest = error.config as AxiosRequestConfig & { _retry?: boolean, _csrfRetry?: boolean };
|
||||
const originalRequest = error.config as AxiosRequestConfig & {
|
||||
_retry?: boolean;
|
||||
_csrfRetry?: boolean;
|
||||
};
|
||||
|
||||
// Handle CSRF token errors
|
||||
if (error.response?.status === 403) {
|
||||
const errorData = error.response?.data as any;
|
||||
if (errorData?.code === "CSRF_TOKEN_MISMATCH" && !originalRequest._csrfRetry) {
|
||||
if (
|
||||
errorData?.code === "CSRF_TOKEN_MISMATCH" &&
|
||||
!originalRequest._csrfRetry
|
||||
) {
|
||||
originalRequest._csrfRetry = true;
|
||||
|
||||
// Try to fetch a new CSRF token and retry
|
||||
|
||||
Reference in New Issue
Block a user