Commit 001fd9e0 authored by Alex Segers's avatar Alex Segers

[AFP-97] 🛂 Implement public and private route components (@asegers)

parent 479b998f
import React from 'react'
import { Redirect, Route, RouteProps } from 'react-router-dom';
import { useGoogleAuth } from 'hooks';
interface CustomRouteProps extends RouteProps {
component: React.ComponentType;
}
export const PublicRoute: React.FC<CustomRouteProps> = ({component: Component, ...rest}) => {
const { isSignedIn } = useGoogleAuth();
return (
<Route {...rest} render={(props: any) => (
!isSignedIn ?
<Component {...props} /> :
<Redirect exact to="/orders" />
)} />
);
};
export const PrivateRoute: React.FC<CustomRouteProps> = ({component: Component, ...rest}) => {
const { isSignedIn } = useGoogleAuth();
return (
<Route {...rest} render={(props: any) => (
isSignedIn ?
<Component {...props }/>:
<Redirect exact from="/orders" to="/" />
)} />
);
};
\ No newline at end of file
export * from './CustomRoutes'
export { default as MainRouter } from './MainRouter'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment