11import React from 'react' ;
2- import { BrowserRouter as Router , Route , Switch , Redirect } from 'react-router-dom' ;
2+ import { BrowserRouter as Router , Route , Switch } from 'react-router-dom' ;
33import Login from '../imports/ui/components/login.jsx' ;
44import Landing from '../imports/ui/components/landing.jsx' ;
55import Navbar from '../imports/ui/components/navbar.jsx' ;
@@ -8,48 +8,28 @@ import Woohoo from '../imports/ui/components/woohoo.jsx';
88import Apply from '../imports/ui/components/apply.jsx' ;
99import ForgotPassword from '../imports/ui/components/forgot_password.jsx' ;
1010import SetPassword from '../imports/ui/components/set_password.jsx' ;
11- import Profile from '../imports/ui/components/dashboard/profile.jsx' ;
1211import Moderator from '../imports/ui/components/moderator.jsx' ;
13- import withUser from '../imports/ui/components/hoc/with-user.jsx' ;
12+ import Profile from '../imports/ui/components/dashboard/profile' ;
13+ import AuthenticatedRoute from '../imports/ui/components/hoc/AuthenticatedRoute' ;
14+ import { AuthProvider } from '../imports/ui/components/hoc/AuthProvider' ;
1415
1516export const renderRoutes = ( ) => (
1617 < Router >
17- < Switch >
18+ < AuthProvider >
1819 < Navbar >
19- < Route exact path = "/" component = { Landing } />
20- < RouteWithUser exact path = "/dashboard" component = { Profile } />
21- < RouteWithOutUser exact path = "/login" component = { Login } />
22- < RouteWithOutUser exact path = "/forgot-password" component = { ForgotPassword } />
23- < RouteWithOutUser exact path = "/enroll-account/:token" component = { SetPassword } />
24- < RouteWithOutUser exact path = "/reset-password/:token" component = { SetPassword } />
25- < RouteWithUser exact path = "/moderator" component = { Moderator } />
26- < Route exact path = "/faq" component = { Faq } />
27- < RouteWithOutUser path = "/apply" component = { Apply } />
28- < Route path = "/woohoo" component = { withUser ( Woohoo ) } />
20+ < Switch >
21+ < AuthenticatedRoute path = "/dashboard" component = { Profile } />
22+ < AuthenticatedRoute path = "/moderator" component = { Moderator } />
23+ < Route path = "/login" component = { Login } />
24+ < Route path = "/forgot-password" component = { ForgotPassword } />
25+ < Route exact path = "/enroll-account/:token" component = { SetPassword } />
26+ < Route exact path = "/reset-password/:token" component = { SetPassword } />
27+ < Route exact path = "/faq" component = { Faq } />
28+ < Route path = "/apply" component = { Apply } />
29+ < Route path = "/woohoo" component = { Woohoo } />
30+ < Route exact path = "/" component = { Landing } />
31+ </ Switch >
2932 </ Navbar >
30- </ Switch >
33+ </ AuthProvider >
3134 </ Router >
3235) ;
33-
34- // All routes where user supposed to be logged in
35- // If user is not logged in, redirect them to login page
36- const RouteWithUser = withUser ( ( { user, component : Component , ...rest } ) => {
37- const { pathname } = window . location ;
38-
39- if ( user ) {
40- return < Route { ...rest } render = { props => < Component { ...props } user = { user } /> } /> ;
41- } else if ( pathname !== '/login' && pathname === rest . path ) {
42- return < Redirect push to = "/login" /> ;
43- }
44- return null ;
45- } ) ;
46-
47- const RouteWithOutUser = withUser ( ( { user, component : Component , ...rest } ) => {
48- const { pathname } = window . location ;
49- if ( ! user ) {
50- return < Route { ...rest } render = { props => < Component { ...props } user = { user } /> } /> ;
51- } else if ( pathname !== '/dashboard' && pathname === rest . path ) {
52- return < Redirect push to = "/dashboard" /> ;
53- }
54- return null ;
55- } ) ;
0 commit comments