Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 2x 9x 9x 2x 7x | // src/components/AdminRoute.tsx
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import type { Profile } from '../types';
export interface AdminRouteProps {
profile: Profile | null;
}
export const AdminRoute: React.FC<AdminRouteProps> = ({ profile }) => {
// An admin is identified by the 'admin' role in their profile.
const isAdmin = profile?.role === 'admin';
if (!isAdmin) {
return <Navigate to="/" replace />;
}
return <Outlet />;
};
|