Starting to resolve the issue on prediction9

This commit is contained in:
Your Name 2026-10-27 10:02:56 +02:00
parent b2e4fbfc5d
commit 415afe8ac8
7 changed files with 484 additions and 113 deletions

View File

@ -4,7 +4,20 @@ server {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; index index.html;
# Vite hashed bundles — safe to cache forever; soft reload (F5) reuses them.
location /assets/ {
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# HTML entry must always revalidate so clients pick up new hashed asset names.
location = /index.html {
add_header Cache-Control "no-cache";
}
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
} }
} }

View File

@ -4,13 +4,16 @@
*/ */
import { CssBaseline, ThemeProvider } from '@mui/material'; import { CssBaseline, ThemeProvider } from '@mui/material';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useMemo } from 'react'; import { lazy, Suspense, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { RouterProvider } from 'react-router-dom'; import { RouterProvider } from 'react-router-dom';
import { createAppTheme } from './theme/theme'; import { createAppTheme } from './theme/theme';
import { router } from './router/router'; import { router } from './router/router';
import { AuthProvider } from '../shared/auth/AuthContext'; import { AuthProvider } from '../shared/auth/AuthContext';
import { SupportWidget } from '../features/support/components/SupportWidget';
const SupportWidget = lazy(() =>
import('../features/support/components/SupportWidget').then((m) => ({ default: m.SupportWidget }))
);
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
@ -33,7 +36,9 @@ function AppProviders() {
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<CssBaseline /> <CssBaseline />
<RouterProvider router={router} /> <RouterProvider router={router} />
<SupportWidget /> <Suspense fallback={null}>
<SupportWidget />
</Suspense>
</ThemeProvider> </ThemeProvider>
</AuthProvider> </AuthProvider>
</QueryClientProvider> </QueryClientProvider>

View File

@ -1,49 +1,113 @@
/** /**
* Client-side route configuration for the web admin console. * Client-side route configuration for the web admin console.
* Defines public login routes, authenticated app shell routes, and admin-only sections. * Heavy feature pages are lazy-loaded so a hard refresh only parses the shell + active route.
*/ */
import { lazy, Suspense, type ComponentType, type ReactNode } from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom'; import { createBrowserRouter, Navigate } from 'react-router-dom';
import { Box, CircularProgress } from '@mui/material';
import { AppShell } from '../../shared/layout/AppShell'; import { AppShell } from '../../shared/layout/AppShell';
import { DashboardPage } from '../../features/dashboard/DashboardPage'; import { RequireAuth } from '../../shared/auth/RequireAuth';
import { OptionsPage } from '../../features/options/OptionsPage';
import { UserManagementPage } from '../../features/users/UserManagementPage';
import { SettingsPage } from '../../features/settings/SettingsPage';
import { LoginPage } from '../../features/auth/LoginPage'; import { LoginPage } from '../../features/auth/LoginPage';
import { SetupPage } from '../../features/auth/SetupPage'; import { SetupPage } from '../../features/auth/SetupPage';
import { RegisterPage } from '../../features/auth/RegisterPage';
import { VerifyEmailPage } from '../../features/auth/VerifyEmailPage'; function lazyNamed<T extends Record<string, unknown>, K extends keyof T>(
import { ForgotPasswordPage } from '../../features/auth/ForgotPasswordPage'; loader: () => Promise<T>,
import { ResetPasswordPage } from '../../features/auth/ResetPasswordPage'; exportName: K
import { CountriesAdminPage } from '../../features/countries/CountriesAdminPage'; ) {
import { RequireAuth } from '../../shared/auth/RequireAuth'; return lazy(async () => {
import { WalletPage } from '../../features/wallet/WalletPage'; const mod = await loader();
import { ProfilePage } from '../../features/profile/ProfilePage'; return { default: mod[exportName] as ComponentType<Record<string, never>> };
import { HomePage } from '../../features/home/HomePage'; });
import { CatalogAdminPage } from '../../features/catalog/CatalogAdminPage'; }
import { TreasuryAdminPage } from '../../features/treasury/TreasuryAdminPage';
import { ApprovalsPage } from '../../features/approvals/ApprovalsPage'; const RegisterPage = lazyNamed(() => import('../../features/auth/RegisterPage'), 'RegisterPage');
import { ApprovalPoliciesPage } from '../../features/approvals/ApprovalPoliciesPage'; const VerifyEmailPage = lazyNamed(() => import('../../features/auth/VerifyEmailPage'), 'VerifyEmailPage');
import { ReferralAdminPage } from '../../features/referral/ReferralAdminPage'; const ForgotPasswordPage = lazyNamed(
import { ReferralRegularizationPage } from '../../features/referral/ReferralRegularizationPage'; () => import('../../features/auth/ForgotPasswordPage'),
import { ReferralPage } from '../../features/referral/ReferralPage'; 'ForgotPasswordPage'
import { ReferralFraudDashboardPage } from '../../features/referral/ReferralFraudDashboardPage'; );
import { TestWalletAdminPage } from '../../features/test-wallet/TestWalletAdminPage'; const ResetPasswordPage = lazyNamed(() => import('../../features/auth/ResetPasswordPage'), 'ResetPasswordPage');
import { ShareCardsAdminPage } from '../../features/share-cards/ShareCardsAdminPage'; const FaqPublicPage = lazyNamed(() => import('../../features/faq/FaqPublicPage'), 'FaqPublicPage');
import { SoloEncouragementAdminPage } from '../../features/solo-encouragement/SoloEncouragementAdminPage'; const ShareResultVerifyPage = lazyNamed(
import { MarketingAdminPage } from '../../features/marketing/MarketingAdminPage'; () => import('../../features/share-cards/ShareResultVerifyPage'),
import { ShareResultVerifyPage } from '../../features/share-cards/ShareResultVerifyPage'; 'ShareResultVerifyPage'
import { SecurityAdminPage } from '../../features/security/SecurityAdminPage'; );
import { ReportsHubPage } from '../../features/reports/ReportsHubPage';
import { ReportDetailPage } from '../../features/reports/ReportDetailPage'; const HomePage = lazyNamed(() => import('../../features/home/HomePage'), 'HomePage');
import { NetworkStatusPage } from '../../features/network/NetworkStatusPage'; const GamePlayRoute = lazyNamed(() => import('../../features/games/GamePlayRoute'), 'GamePlayRoute');
import { SupportAdminPage } from '../../features/support/SupportAdminPage'; const WalletPage = lazyNamed(() => import('../../features/wallet/WalletPage'), 'WalletPage');
import { FaqPublicPage } from '../../features/faq/FaqPublicPage'; const ReferralPage = lazyNamed(() => import('../../features/referral/ReferralPage'), 'ReferralPage');
import { FaqPage } from '../../features/faq/FaqPage'; const ProfilePage = lazyNamed(() => import('../../features/profile/ProfilePage'), 'ProfilePage');
import { FaqAdminPage } from '../../features/faq/FaqAdminPage'; const FaqPage = lazyNamed(() => import('../../features/faq/FaqPage'), 'FaqPage');
import { RoleManagementPage } from '../../features/rbac/RoleManagementPage';
import { AdminUsersPage } from '../../features/rbac/AdminUsersPage'; const SupportAdminPage = lazyNamed(() => import('../../features/support/SupportAdminPage'), 'SupportAdminPage');
import { AdminUserPermissionsPage } from '../../features/rbac/AdminUserPermissionsPage'; const FaqAdminPage = lazyNamed(() => import('../../features/faq/FaqAdminPage'), 'FaqAdminPage');
import { GamePlayRoute } from '../../features/games/GamePlayRoute';
const DashboardPage = lazyNamed(() => import('../../features/dashboard/DashboardPage'), 'DashboardPage');
const OptionsPage = lazyNamed(() => import('../../features/options/OptionsPage'), 'OptionsPage');
const UserManagementPage = lazyNamed(
() => import('../../features/users/UserManagementPage'),
'UserManagementPage'
);
const ReportsHubPage = lazyNamed(() => import('../../features/reports/ReportsHubPage'), 'ReportsHubPage');
const ReportDetailPage = lazyNamed(() => import('../../features/reports/ReportDetailPage'), 'ReportDetailPage');
const SettingsPage = lazyNamed(() => import('../../features/settings/SettingsPage'), 'SettingsPage');
const CatalogAdminPage = lazyNamed(() => import('../../features/catalog/CatalogAdminPage'), 'CatalogAdminPage');
const TreasuryAdminPage = lazyNamed(() => import('../../features/treasury/TreasuryAdminPage'), 'TreasuryAdminPage');
const ApprovalsPage = lazyNamed(() => import('../../features/approvals/ApprovalsPage'), 'ApprovalsPage');
const ApprovalPoliciesPage = lazyNamed(
() => import('../../features/approvals/ApprovalPoliciesPage'),
'ApprovalPoliciesPage'
);
const SecurityAdminPage = lazyNamed(() => import('../../features/security/SecurityAdminPage'), 'SecurityAdminPage');
const ReferralAdminPage = lazyNamed(() => import('../../features/referral/ReferralAdminPage'), 'ReferralAdminPage');
const ReferralRegularizationPage = lazyNamed(
() => import('../../features/referral/ReferralRegularizationPage'),
'ReferralRegularizationPage'
);
const ReferralFraudDashboardPage = lazyNamed(
() => import('../../features/referral/ReferralFraudDashboardPage'),
'ReferralFraudDashboardPage'
);
const TestWalletAdminPage = lazyNamed(
() => import('../../features/test-wallet/TestWalletAdminPage'),
'TestWalletAdminPage'
);
const ShareCardsAdminPage = lazyNamed(
() => import('../../features/share-cards/ShareCardsAdminPage'),
'ShareCardsAdminPage'
);
const SoloEncouragementAdminPage = lazyNamed(
() => import('../../features/solo-encouragement/SoloEncouragementAdminPage'),
'SoloEncouragementAdminPage'
);
const MarketingAdminPage = lazyNamed(
() => import('../../features/marketing/MarketingAdminPage'),
'MarketingAdminPage'
);
const CountriesAdminPage = lazyNamed(
() => import('../../features/countries/CountriesAdminPage'),
'CountriesAdminPage'
);
const NetworkStatusPage = lazyNamed(() => import('../../features/network/NetworkStatusPage'), 'NetworkStatusPage');
const RoleManagementPage = lazyNamed(() => import('../../features/rbac/RoleManagementPage'), 'RoleManagementPage');
const AdminUsersPage = lazyNamed(() => import('../../features/rbac/AdminUsersPage'), 'AdminUsersPage');
const AdminUserPermissionsPage = lazyNamed(
() => import('../../features/rbac/AdminUserPermissionsPage'),
'AdminUserPermissionsPage'
);
function RouteFallback() {
return (
<Box sx={{ display: 'grid', placeItems: 'center', minHeight: 240, width: '100%' }}>
<CircularProgress size={28} />
</Box>
);
}
function L({ children }: { children: ReactNode }) {
return <Suspense fallback={<RouteFallback />}>{children}</Suspense>;
}
/** Browser router instance with login, dashboard, options, and admin route trees. */ /** Browser router instance with login, dashboard, options, and admin route trees. */
export const router = createBrowserRouter([ export const router = createBrowserRouter([
@ -57,27 +121,51 @@ export const router = createBrowserRouter([
}, },
{ {
path: '/register', path: '/register',
element: <RegisterPage />, element: (
<L>
<RegisterPage />
</L>
),
}, },
{ {
path: '/verify-email', path: '/verify-email',
element: <VerifyEmailPage />, element: (
<L>
<VerifyEmailPage />
</L>
),
}, },
{ {
path: '/forgot-password', path: '/forgot-password',
element: <ForgotPasswordPage />, element: (
<L>
<ForgotPasswordPage />
</L>
),
}, },
{ {
path: '/reset-password', path: '/reset-password',
element: <ResetPasswordPage />, element: (
<L>
<ResetPasswordPage />
</L>
),
}, },
{ {
path: '/faq', path: '/faq',
element: <FaqPublicPage />, element: (
<L>
<FaqPublicPage />
</L>
),
}, },
{ {
path: '/share/r/:token', path: '/share/r/:token',
element: <ShareResultVerifyPage />, element: (
<L>
<ShareResultVerifyPage />
</L>
),
}, },
{ {
path: '/', path: '/',
@ -87,45 +175,262 @@ export const router = createBrowserRouter([
element: <AppShell />, element: <AppShell />,
children: [ children: [
{ index: true, element: <Navigate to="/home" replace /> }, { index: true, element: <Navigate to="/home" replace /> },
{ path: 'home', element: <HomePage /> }, {
{ path: 'games/:slug', element: <GamePlayRoute /> }, path: 'home',
{ path: 'wallet', element: <WalletPage /> }, element: (
{ path: 'referral', element: <ReferralPage /> }, <L>
{ path: 'profile', element: <ProfilePage /> }, <HomePage />
{ path: 'help/faq', element: <FaqPage /> }, </L>
),
},
{
path: 'games/:slug',
element: (
<L>
<GamePlayRoute />
</L>
),
},
{
path: 'wallet',
element: (
<L>
<WalletPage />
</L>
),
},
{
path: 'referral',
element: (
<L>
<ReferralPage />
</L>
),
},
{
path: 'profile',
element: (
<L>
<ProfilePage />
</L>
),
},
{
path: 'help/faq',
element: (
<L>
<FaqPage />
</L>
),
},
{ {
element: <RequireAuth staffOnly />, element: <RequireAuth staffOnly />,
children: [ children: [
{ path: 'admin/support', element: <SupportAdminPage /> }, {
{ path: 'admin/faq', element: <FaqAdminPage /> }, path: 'admin/support',
element: (
<L>
<SupportAdminPage />
</L>
),
},
{
path: 'admin/faq',
element: (
<L>
<FaqAdminPage />
</L>
),
},
], ],
}, },
{ {
element: <RequireAuth adminOnly />, element: <RequireAuth adminOnly />,
children: [ children: [
{ path: 'dashboard', element: <DashboardPage /> }, {
{ path: 'options', element: <OptionsPage /> }, path: 'dashboard',
{ path: 'admin/users', element: <UserManagementPage /> }, element: (
{ path: 'admin/reports', element: <ReportsHubPage /> }, <L>
{ path: 'admin/reports/:reportKey', element: <ReportDetailPage /> }, <DashboardPage />
{ path: 'admin/settings', element: <SettingsPage /> }, </L>
{ path: 'admin/catalog', element: <CatalogAdminPage /> }, ),
{ path: 'admin/treasury', element: <TreasuryAdminPage /> }, },
{ path: 'admin/approvals', element: <ApprovalsPage /> }, {
{ path: 'admin/approval-policies', element: <ApprovalPoliciesPage /> }, path: 'options',
{ path: 'admin/security', element: <SecurityAdminPage /> }, element: (
{ path: 'admin/referral', element: <ReferralAdminPage /> }, <L>
{ path: 'admin/referral/regularization', element: <ReferralRegularizationPage /> }, <OptionsPage />
{ path: 'admin/referral/fraud', element: <ReferralFraudDashboardPage /> }, </L>
{ path: 'admin/test-wallet', element: <TestWalletAdminPage /> }, ),
{ path: 'admin/share-cards', element: <ShareCardsAdminPage /> }, },
{ path: 'admin/solo-encouragement', element: <SoloEncouragementAdminPage /> }, {
{ path: 'admin/marketing', element: <MarketingAdminPage /> }, path: 'admin/users',
{ path: 'admin/countries', element: <CountriesAdminPage /> }, element: (
{ path: 'admin/network', element: <NetworkStatusPage /> }, <L>
{ path: 'admin/rbac', element: <RoleManagementPage /> }, <UserManagementPage />
{ path: 'admin/admin-users', element: <AdminUsersPage /> }, </L>
{ path: 'admin/admin-users/:userId/permissions', element: <AdminUserPermissionsPage /> }, ),
},
{
path: 'admin/reports',
element: (
<L>
<ReportsHubPage />
</L>
),
},
{
path: 'admin/reports/:reportKey',
element: (
<L>
<ReportDetailPage />
</L>
),
},
{
path: 'admin/settings',
element: (
<L>
<SettingsPage />
</L>
),
},
{
path: 'admin/catalog',
element: (
<L>
<CatalogAdminPage />
</L>
),
},
{
path: 'admin/treasury',
element: (
<L>
<TreasuryAdminPage />
</L>
),
},
{
path: 'admin/approvals',
element: (
<L>
<ApprovalsPage />
</L>
),
},
{
path: 'admin/approval-policies',
element: (
<L>
<ApprovalPoliciesPage />
</L>
),
},
{
path: 'admin/security',
element: (
<L>
<SecurityAdminPage />
</L>
),
},
{
path: 'admin/referral',
element: (
<L>
<ReferralAdminPage />
</L>
),
},
{
path: 'admin/referral/regularization',
element: (
<L>
<ReferralRegularizationPage />
</L>
),
},
{
path: 'admin/referral/fraud',
element: (
<L>
<ReferralFraudDashboardPage />
</L>
),
},
{
path: 'admin/test-wallet',
element: (
<L>
<TestWalletAdminPage />
</L>
),
},
{
path: 'admin/share-cards',
element: (
<L>
<ShareCardsAdminPage />
</L>
),
},
{
path: 'admin/solo-encouragement',
element: (
<L>
<SoloEncouragementAdminPage />
</L>
),
},
{
path: 'admin/marketing',
element: (
<L>
<MarketingAdminPage />
</L>
),
},
{
path: 'admin/countries',
element: (
<L>
<CountriesAdminPage />
</L>
),
},
{
path: 'admin/network',
element: (
<L>
<NetworkStatusPage />
</L>
),
},
{
path: 'admin/rbac',
element: (
<L>
<RoleManagementPage />
</L>
),
},
{
path: 'admin/admin-users',
element: (
<L>
<AdminUsersPage />
</L>
),
},
{
path: 'admin/admin-users/:userId/permissions',
element: (
<L>
<AdminUserPermissionsPage />
</L>
),
},
], ],
}, },
], ],

View File

@ -5,7 +5,6 @@ import {
useRef, useRef,
useState, useState,
type PointerEvent as ReactPointerEvent, type PointerEvent as ReactPointerEvent,
type WheelEvent as ReactWheelEvent,
} from 'react'; } from 'react';
import { import {
Box, Box,
@ -277,25 +276,35 @@ export function ReferralTreeView({
dragRef.current = null; dragRef.current = null;
}; };
const onWheel = (e: ReactWheelEvent) => { // Native non-passive wheel listener — React's onWheel is passive and cannot preventDefault.
e.preventDefault(); const detachWheelRef = useRef<(() => void) | null>(null);
const el = viewportRef.current; const setViewportRef = useCallback((node: HTMLDivElement | null) => {
if (!el) return; detachWheelRef.current?.();
const rect = el.getBoundingClientRect(); detachWheelRef.current = null;
const fx = e.clientX - rect.left; viewportRef.current = node;
const fy = e.clientY - rect.top; if (!node) return;
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1; const onWheel = (e: WheelEvent) => {
setTransform((prev) => { e.preventDefault();
const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor)); const rect = node.getBoundingClientRect();
const sceneX = (fx - prev.x) / prev.scale; const fx = e.clientX - rect.left;
const sceneY = (fy - prev.y) / prev.scale; const fy = e.clientY - rect.top;
return { const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
scale: nextScale, setTransform((prev) => {
x: fx - sceneX * nextScale, const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor));
y: fy - sceneY * nextScale, const sceneX = (fx - prev.x) / prev.scale;
}; const sceneY = (fy - prev.y) / prev.scale;
}); return {
}; scale: nextScale,
x: fx - sceneX * nextScale,
y: fy - sceneY * nextScale,
};
});
};
node.addEventListener('wheel', onWheel, { passive: false });
detachWheelRef.current = () => node.removeEventListener('wheel', onWheel);
}, []);
useEffect(() => () => detachWheelRef.current?.(), []);
const directRoots = childMap.get(rootUserId) ?? []; const directRoots = childMap.get(rootUserId) ?? [];
if (directRoots.length === 0 && members.length === 0) { if (directRoots.length === 0 && members.length === 0) {
@ -335,12 +344,11 @@ export function ReferralTreeView({
</Typography> </Typography>
<Box <Box
ref={viewportRef} ref={setViewportRef}
onPointerDown={onPointerDown} onPointerDown={onPointerDown}
onPointerMove={onPointerMove} onPointerMove={onPointerMove}
onPointerUp={onPointerUp} onPointerUp={onPointerUp}
onPointerCancel={onPointerUp} onPointerCancel={onPointerUp}
onWheel={onWheel}
sx={{ sx={{
position: 'absolute', position: 'absolute',
inset: 0, inset: 0,

View File

@ -5,14 +5,14 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import './shared/i18n'; import './shared/i18n';
import { initSentry } from './shared/observability/sentry';
import { App } from './app/App'; import { App } from './app/App';
import './styles/global.css'; import './styles/global.css';
initSentry();
ReactDOM.createRoot(document.getElementById('root')!).render( ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
</React.StrictMode> </React.StrictMode>
); );
// Observability after first paint — do not block boot on Sentry SDK parse/init.
void import('./shared/observability/sentry').then(({ initSentry }) => initSentry());

View File

@ -2,10 +2,11 @@
* React context for authentication state in the web admin console. * React context for authentication state in the web admin console.
*/ */
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react'; import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
import { Box, CircularProgress } from '@mui/material';
import { clearAuth, readAuth, writeAuth } from './tokenStorage'; import { clearAuth, readAuth, writeAuth } from './tokenStorage';
import { hasAdminAccess, hasStaffAccess, hasAdminPanelAccess } from './roleAccess'; import { hasAdminAccess, hasStaffAccess, hasAdminPanelAccess } from './roleAccess';
import { hasPermission as checkPermission } from './permissions'; import { hasPermission as checkPermission } from './permissions';
import { ensureFreshAccessToken, logoutSession } from '../services/api'; import { ensureFreshAccessToken, isAccessTokenExpiringSoon, logoutSession } from '../services/api';
export type AuthState = { export type AuthState = {
accessToken: string | null; accessToken: string | null;
@ -18,7 +19,7 @@ export type AuthState = {
type AuthContextValue = { type AuthContextValue = {
auth: AuthState; auth: AuthState;
/** False until boot refresh finishes — avoid firing protected calls with a stale JWT. */ /** False only while a network refresh is in flight for an expiring session. */
authReady: boolean; authReady: boolean;
isAuthenticated: boolean; isAuthenticated: boolean;
isAdmin: boolean; isAdmin: boolean;
@ -35,23 +36,34 @@ type AuthContextValue = {
const AuthContext = createContext<AuthContextValue | null>(null); const AuthContext = createContext<AuthContextValue | null>(null);
function sessionNeedsNetworkRefresh(): boolean {
const a = readAuth();
if (!a.refreshToken && !a.accessToken) return false;
return isAccessTokenExpiringSoon(a.accessToken, 60);
}
export function AuthProvider({ children }: { children: React.ReactNode }) { export function AuthProvider({ children }: { children: React.ReactNode }) {
const [auth, setAuthState] = useState<AuthState>(() => readAuth()); const [auth, setAuthState] = useState<AuthState>(() => readAuth());
const [authReady, setAuthReady] = useState(false); // Do not block the whole app when the access token is still valid.
const [authReady, setAuthReady] = useState(() => !sessionNeedsNetworkRefresh());
useEffect(() => { useEffect(() => {
let cancelled = false; let cancelled = false;
void (async () => { void (async () => {
const hadSession = Boolean(readAuth().refreshToken || readAuth().accessToken); const hadSession = Boolean(readAuth().refreshToken || readAuth().accessToken);
if (!sessionNeedsNetworkRefresh()) {
if (!cancelled) {
setAuthState(readAuth());
setAuthReady(true);
}
return;
}
const token = await ensureFreshAccessToken(); const token = await ensureFreshAccessToken();
if (cancelled) return; if (cancelled) return;
if (token) { if (token) {
setAuthState(readAuth()); setAuthState(readAuth());
} else if (hadSession && !readAuth().refreshToken) { } else if (hadSession) {
clearAuth();
setAuthState(readAuth());
} else if (hadSession && !token) {
// Refresh failed (revoked / secret rotated) — clear so UI redirects to login.
clearAuth(); clearAuth();
setAuthState(readAuth()); setAuthState(readAuth());
} else { } else {
@ -105,7 +117,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}, [auth, authReady]); }, [auth, authReady]);
if (!authReady) { if (!authReady) {
return null; return (
<Box sx={{ minHeight: '100vh', display: 'grid', placeItems: 'center' }}>
<CircularProgress size={32} />
</Box>
);
} }
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>; return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;

View File

@ -6,5 +6,29 @@ export default defineConfig({
server: { server: {
port: 5173, port: 5173,
}, },
build: {
// Split large vendor libs so hard refresh can download/parse them in parallel
// and soft reload can reuse cached chunks across deploys that only change app code.
rollupOptions: {
output: {
manualChunks(id) {
if (!id.includes('node_modules')) return;
if (id.includes('@mui') || id.includes('@emotion')) return 'mui';
if (
id.includes('node_modules/react/') ||
id.includes('node_modules/react-dom/') ||
id.includes('node_modules/scheduler/') ||
id.includes('react-router')
) {
return 'react';
}
if (id.includes('i18next')) return 'i18n';
if (id.includes('@tanstack/react-query')) return 'query';
if (id.includes('@sentry')) return 'sentry';
return 'vendor';
},
},
},
},
}); });