Files
lettersoup-online/002_source/cms/src/components/auth/strategy-guard.tsx
louiscklaw 6c931c1fe8 build ok,
2025-04-14 09:26:24 +08:00

26 lines
708 B
TypeScript

import * as React from 'react';
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import { config } from '@/config';
import type { AuthStrategy } from '@/lib/auth/strategy';
interface StrategyGuardProps {
children: React.ReactNode;
expected: keyof typeof AuthStrategy;
}
export function StrategyGuard({ children, expected }: StrategyGuardProps): React.JSX.Element {
if (config.auth.strategy !== expected) {
return (
<Box sx={{ p: 3 }}>
<Alert color="error">
To render this page, you need to configure the auth strategy to &quot;{expected}&quot;
</Alert>
</Box>
);
}
return <React.Fragment>{children}</React.Fragment>;
}