fix: evita logout al cambiar de tenant (race condition refresh token)

This commit is contained in:
Horux Dev
2026-06-22 21:47:13 +00:00
parent 3c7758a599
commit cc002adbd2
4 changed files with 80 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ import { Header } from '@/components/layouts/header';
import { Card, CardContent, CardHeader, CardTitle, Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '@horux/shared-ui';
import { getMyTenants, addMyTenant, type MyTenantDetailed } from '@/lib/api/tenants';
import { switchTenant } from '@/lib/api/auth';
import { cancelAllApiRequests } from '@/lib/api/client';
import { useAuthStore } from '@/stores/auth-store';
import { formatCurrency } from '@/lib/utils';
import { Building2, Plus, Crown, ArrowRight, Loader2, AlertCircle, CheckCircle2 } from 'lucide-react';
@@ -61,6 +62,9 @@ export default function MisEmpresasPage() {
router.push('/dashboard');
return;
}
// 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);