diff --git a/application/src/router/appRouter.js b/application/src/router/appRouter.js index 23bbe273..4b36f2fe 100644 --- a/application/src/router/appRouter.js +++ b/application/src/router/appRouter.js @@ -1,14 +1,17 @@ import React from 'react'; import { BrowserRouter as Router, Route } from 'react-router-dom'; import { Main, Login, OrderForm, ViewOrders } from '../components'; +import GuardedRoute from './guard.js'; + const AppRouter = (props) => { + console.log(props); return ( - - + + ); } diff --git a/application/src/router/guard.js b/application/src/router/guard.js new file mode 100644 index 00000000..42a894bb --- /dev/null +++ b/application/src/router/guard.js @@ -0,0 +1,22 @@ +import React from 'react'; +import { Route, Redirect } from 'react-router-dom'; +import { connect } from 'react-redux'; + +const mapStateToProps = (state) => ({ + auth: state.auth, +}) + +const GuardedRoute = (props) => { + const { component: Component, ...rest } = props; + + const render = props => { + console.log(props.auth.token) + if (!props.auth.token) { + return ; + } + return ; + }; + return ; +} + +export default connect(mapStateToProps, null)(GuardedRoute); \ No newline at end of file