New token arch

This commit is contained in:
Urtzi Alfaro
2026-01-10 21:45:37 +01:00
parent cc53037552
commit bf1db7cb9e
26 changed files with 1751 additions and 107 deletions

View File

@@ -3,7 +3,7 @@ import { Crown, Users, MapPin, Package, TrendingUp, RefreshCw, AlertCircle, Chec
import { Button, Card, Badge, Modal } from '../../../../components/ui';
import { DialogModal } from '../../../../components/ui/DialogModal/DialogModal';
import { PageHeader } from '../../../../components/layout';
import { useAuthUser } from '../../../../stores/auth.store';
import { useAuthUser, useAuthActions } from '../../../../stores/auth.store';
import { useCurrentTenant } from '../../../../stores';
import { showToast } from '../../../../utils/toast';
import { subscriptionService, type UsageSummary, type AvailablePlans } from '../../../../api';
@@ -22,6 +22,7 @@ const SubscriptionPage: React.FC = () => {
const user = useAuthUser();
const currentTenant = useCurrentTenant();
const { notifySubscriptionChanged } = useSubscriptionEvents();
const { refreshAuth } = useAuthActions();
const { t } = useTranslation('subscription');
const [usageSummary, setUsageSummary] = useState<UsageSummary | null>(null);
@@ -144,6 +145,17 @@ const SubscriptionPage: React.FC = () => {
// Invalidate cache to ensure fresh data on next fetch
subscriptionService.invalidateCache();
// NEW: Force token refresh to get new JWT with updated subscription
if (result.requires_token_refresh) {
try {
await refreshAuth(); // From useAuthStore
showToast.info('Sesión actualizada con nuevo plan');
} catch (refreshError) {
console.warn('Token refresh failed, user may need to re-login:', refreshError);
// Don't block - the subscription is updated, just the JWT is stale
}
}
// Broadcast subscription change event to refresh sidebar and other components
notifySubscriptionChanged();

View File

@@ -213,7 +213,7 @@ const DemoPage = () => {
is_verified: true,
created_at: new Date().toISOString(),
tenant_id: sessionData.virtual_tenant_id,
});
}, tier); // NEW: Pass subscription tier to setDemoAuth
console.log('✅ [DemoPage] Demo auth set in store');
} else {