Merge branch 'develop' of github.com:Tria-plc/edr-platform into feat/customer_registration

This commit is contained in:
yaschalew
2026-05-18 12:10:12 +03:00
3 changed files with 68 additions and 15 deletions

View File

@@ -28,7 +28,12 @@ import TrackingPage from "./pages/tracking/TrackingPage";
import BillingPage from "./pages/billing/BillingPage";
import TrainsPage from "./pages/trains/TrainsPage";
import DashboardPage from "./pages/dashboard/DashboardPage";
import { IamLoginPage, LoadingScreen, useAuth } from "@tria-plc/iamui-common";
import {
IamLoginPage,
LoadingScreen,
useAuth,
useAuthUser,
} from "@tria-plc/iamui-common";
import CustomersPage from "./pages/customers/CustomersPage";
import CustomerDetailPage from "./pages/customers/CustomerDetailPage";
import NewCustomerPage from "./pages/customers/NewCustomerPage";
@@ -53,6 +58,7 @@ const App = () => {
const navigate = useNavigate();
const location = useLocation();
const { user, loading } = useAuth();
const { logout } = useAuthUser();
if (loading) {
return <LoadingScreen />;
@@ -67,9 +73,19 @@ const App = () => {
);
}
if (location.pathname === "/auth") {
return <Navigate to="/" replace />;
}
const displayName = user?.name?.en || user?.username || user?.email || "User";
const userEmail = user?.email;
const handleLogout = () => {
// Best-effort server-side session invalidation; local cleanup always runs
// so a failed API call (e.g. expired token) never leaves the user stuck.
logout();
["auth-token", "refresh-token"].forEach((name) => {
document.cookie = `${name}=; Max-Age=0; path=/`;
});
localStorage.clear();
window.location.replace("/auth");
};
return (
<DashboardLayout
@@ -78,6 +94,9 @@ const App = () => {
activeHref={location.pathname}
onNavigate={navigate}
enableThemeToggle
userName={displayName}
userEmail={userEmail}
onLogout={handleLogout}
>
<Routes>
<Route path="/" element={<DashboardPage />} />

View File

@@ -13,6 +13,19 @@ import {
axiosInstance,
} from "@tria-plc/iamui-common";
// Purge cookies that were stored as the literal string "undefined" before the
// envelope interceptor fix. Without this, stale sessions would keep sending
// "Authorization: Bearer undefined" and get 401 JsonWebTokenError forever.
["auth-token", "refresh-token"].forEach((name) => {
const entry = document.cookie
.split("; ")
.find((c) => c.startsWith(`${name}=`));
const value = entry?.split("=").slice(1).join("=");
if (value === "undefined" || value === "null" || value === "") {
document.cookie = `${name}=; Max-Age=0; path=/`;
}
});
const queryClient = new QueryClient();
window.__IAM_CONFIG__ = {
apiUrl: `${import.meta.env.VITE_BASE_API_URL}/api`,