fix: evita logout al cambiar de tenant (race condition refresh token)
This commit is contained in:
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useAuthStore } from '@/stores/auth-store';
|
||||
import { switchTenant } from '@/lib/api/auth';
|
||||
import { cancelAllApiRequests } from '@/lib/api/client';
|
||||
import { Building2, ChevronDown, Check, Loader2, Crown } from 'lucide-react';
|
||||
import { cn } from '@horux/shared-ui';
|
||||
import { isGlobalAdminRfc } from '@horux/shared';
|
||||
@@ -44,6 +45,9 @@ export function MembershipSwitcher() {
|
||||
const handleSwitch = async (tenantId: string) => {
|
||||
if (tenantId === user?.tenantId) { setOpen(false); return; }
|
||||
setSwitching(true);
|
||||
// Cancela requests pendientes para evitar que intenten refrescar con el
|
||||
// token que switchTenant va a invalidar.
|
||||
cancelAllApiRequests();
|
||||
try {
|
||||
const res = await switchTenant(tenantId);
|
||||
setTokens(res.accessToken, res.refreshToken);
|
||||
|
||||
Reference in New Issue
Block a user