setting pilot page behind protected route (#44)
This commit was merged in pull request #44.
This commit is contained in:
@@ -1,56 +1,32 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Route, Routes } from 'react-router-dom';
|
||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||
import Pilots from './components/pilots/Pilots';
|
||||
import Logbook from './components/logbook/Logbook';
|
||||
import { useAppContext } from './hooks/appContext/UseAppContext';
|
||||
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { useHttpClient } from './hooks/httpClient/UseHttpClient';
|
||||
import { useFeatureFlag } from './hooks/featureFlag/UseFeatureFlag';
|
||||
import SiteNav from './components/siteNav/SiteNav';
|
||||
import { IPublicClientApplication } from '@azure/msal-browser';
|
||||
import { MsalProvider } from '@azure/msal-react';
|
||||
import { useIsAuthenticated } from '@azure/msal-react';
|
||||
|
||||
interface AppProps {
|
||||
pca: IPublicClientApplication
|
||||
interface ProtectedRouteProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const App: React.FC<AppProps> = ({ pca }: AppProps) => {
|
||||
const httpClient: AxiosInstance = useHttpClient();
|
||||
const appContext = useAppContext();
|
||||
const App = () => {
|
||||
const isAuthenticated = useIsAuthenticated()
|
||||
|
||||
// useEffect(() => {
|
||||
// const getFeatureFlags = async () => {
|
||||
// try {
|
||||
// const featureFlagKeys: string = 'flying-pilots';
|
||||
// const response: AxiosResponse = await httpClient.get(
|
||||
// `api/featureFlags?keys=${featureFlagKeys}&label=${import.meta.env.MODE}`
|
||||
// );
|
||||
// const featureFlags: { key: string; enabled: boolean }[] = response.data;
|
||||
|
||||
// if (featureFlags.length > 0) {
|
||||
// appContext.dispatch({
|
||||
// type: 'SET_FEATURE_FLAGS',
|
||||
// payload: featureFlags
|
||||
// });
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.log(error);
|
||||
// }
|
||||
// };
|
||||
|
||||
// getFeatureFlags();
|
||||
// }, []);
|
||||
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
|
||||
return isAuthenticated ? children : <Navigate to='/' />
|
||||
}
|
||||
|
||||
return (
|
||||
<MsalProvider instance={pca}>
|
||||
<>
|
||||
<SiteNav />
|
||||
<Routes>
|
||||
{/* {useFeatureFlag('flying-pilots')?.enabled && ( */}
|
||||
<Route path="/pilots" element={<Pilots />} />
|
||||
{/* )} */}
|
||||
<Route path="/pilots" element={
|
||||
<ProtectedRoute>
|
||||
<Pilots />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/" element={<Logbook />} />
|
||||
</Routes>
|
||||
</MsalProvider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user