All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 57m50s
20 lines
491 B
TypeScript
20 lines
491 B
TypeScript
// 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 />;
|
|
};
|