mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
- Implemented ExamStageActions component to manage actions related to exam booking and payment based on application status. - Added mock-base-query for development, providing a partial mock backend for various API endpoints. - Introduced mock-data for simulating responses in the mock-base-query, covering profiles, vessels, applications, licenses, exams, and notifications.
24 lines
839 B
TypeScript
24 lines
839 B
TypeScript
import Cookies from 'js-cookie';
|
|
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
|
import type { ReactNode } from 'react';
|
|
import { authStorage } from '../utils/auth-storage';
|
|
|
|
interface ProtectedRouteProps {
|
|
children?: ReactNode;
|
|
loginPath?: string;
|
|
}
|
|
|
|
export function ProtectedRoute({ children, loginPath = '/login' }: ProtectedRouteProps) {
|
|
const location = useLocation();
|
|
// `authStorage` is already scoped to this app; the bare key is only the
|
|
// legacy pre-prefix session. Never read a sibling app's token — that is how
|
|
// a backoffice tab ends up authenticated as a portal applicant.
|
|
const token = authStorage.getToken() ?? Cookies.get('auth-token');
|
|
|
|
if (!token) {
|
|
return <Navigate to={loginPath} state={{ from: location }} replace />;
|
|
}
|
|
|
|
return children ? <>{children}</> : <Outlet />;
|
|
}
|