RezinaLMS-Admin/src/App.tsx

65 lines
1.6 KiB
TypeScript

import { Toaster } from "sonner"
import { AppRoutes } from "./app/AppRoutes"
import { useTheme } from "./contexts/ThemeContext.shared"
import { clearTeamSession } from "./lib/teamAuthStorage"
const SESSION_KEY = "rezina_session_active"
/**
* Clear persisted team tokens when this browser tab session is new.
* Must run before the first render so AppLayout/Login never mount protected
* fetches against a stale localStorage session and toast "Authorization header missing".
*/
function bootstrapBrowserSession() {
try {
if (!sessionStorage.getItem(SESSION_KEY)) {
clearTeamSession()
sessionStorage.setItem(SESSION_KEY, "1")
}
} catch {
// sessionStorage unavailable (private mode quirks) — leave tokens alone
}
}
bootstrapBrowserSession()
function AppToaster() {
const { resolvedTheme } = useTheme()
return (
<Toaster
position="top-center"
theme={resolvedTheme}
closeButton
expand={false}
visibleToasts={4}
offset={20}
gap={12}
duration={4200}
toastOptions={{
classNames: {
toast: "rezina-toast",
title: "rezina-toast__title",
description: "rezina-toast__description",
actionButton: "rezina-toast__action",
cancelButton: "rezina-toast__cancel",
closeButton: "rezina-toast__close",
success: "rezina-toast--success",
error: "rezina-toast--error",
warning: "rezina-toast--warning",
info: "rezina-toast--info",
},
}}
/>
)
}
export default function App() {
return (
<>
<AppRoutes />
<AppToaster />
</>
)
}