removed old beta

This commit is contained in:
jackiettran
2025-09-19 22:33:44 -04:00
parent 649289bf90
commit 6199609a4d
5 changed files with 524 additions and 33 deletions

View File

@@ -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