File tree Expand file tree Collapse file tree 4 files changed +64
-9
lines changed Expand file tree Collapse file tree 4 files changed +64
-9
lines changed Original file line number Diff line number Diff line change @@ -11,18 +11,59 @@ import Register from './views/pages/register/Register';
1111import CreateNewEvent from './components/CreateNewEvent' ;
1212import Settings from './views/pages/settings/Settings' ;
1313import LandingPage from './views/pages/HomeView/LandingPage' ;
14+ import AuthGuard from './components/auth/AuthGuard' ;
1415
1516const renderRoutes = ( ) => (
1617 < Suspense fallback = { < LoadingScreen /> } >
1718 < Switch >
1819 < Route path = "/" exact render = { ( ) => < LandingPage /> } />
1920 < Route path = "/register" exact render = { ( ) => < Register /> } />
20- < Route path = "/dashboard" exact render = { ( ) => < Navigation /> } />
21- < Route path = "/profile" exact render = { ( ) => < Profile /> } />
21+ < Route
22+ path = "/dashboard"
23+ exact
24+ render = { ( ) => (
25+ < AuthGuard >
26+ < Navigation />
27+ </ AuthGuard >
28+ ) }
29+ />
30+ < Route
31+ path = "/profile"
32+ exact
33+ render = { ( ) => (
34+ < AuthGuard >
35+ < Profile />
36+ </ AuthGuard >
37+ ) }
38+ />
2239 < Route path = "/events" exact render = { ( ) => < EventDefaultPage /> } />
23- < Route path = "/events/:eventID" exact render = { ( ) => < IndividualEvent /> } />
24- < Route path = "/createEvent" exact render = { ( ) => < CreateNewEvent /> } />
25- < Route path = "/settings" exact render = { ( ) => < Settings /> } />
40+ < Route
41+ path = "/events/:eventID"
42+ exact
43+ render = { ( ) => (
44+ < AuthGuard >
45+ < IndividualEvent />
46+ </ AuthGuard >
47+ ) }
48+ />
49+ < Route
50+ path = "/createEvent"
51+ exact
52+ render = { ( ) => (
53+ < AuthGuard >
54+ < CreateNewEvent />
55+ </ AuthGuard >
56+ ) }
57+ />
58+ < Route
59+ path = "/settings"
60+ exact
61+ render = { ( ) => (
62+ < AuthGuard >
63+ < Settings />
64+ </ AuthGuard >
65+ ) }
66+ />
2667 < Route path = "*" exact render = { ( ) => < Error404View /> } />
2768 </ Switch >
2869 </ Suspense >
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ function Auth({ children }) {
1515
1616 authService . handleAuthentication ( ) ;
1717 authService . firebase . auth ( ) . onAuthStateChanged ( user => {
18+ if ( user ) {
19+ const userItems = JSON . stringify ( {
20+ displayName : user . displayName ,
21+ photoURL : user . photoURL ,
22+ uid : user . uid
23+ } ) ;
24+ localStorage . setItem ( 'causefolioUser' , userItems ) ;
25+ } else {
26+ localStorage . setItem ( 'causefolioUser' , user ) ;
27+ }
1828 dispatch ( setUserData ( user ) ) ;
1929 user . getIdToken ( ) . then ( token => {
2030 authService . setSession ( token ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { useSelector } from 'react-redux' ;
32import { Redirect } from 'react-router-dom' ;
43import PropTypes from 'prop-types' ;
4+ import { getLoggedUser } from 'src/services/authService' ;
55
66function AuthGuard ( { children } ) {
7- const account = useSelector ( state => state . account ) ;
7+ const user = getLoggedUser ( ) ;
88
9- if ( ! account . user ) {
10- return < Redirect to = "/login " /> ;
9+ if ( ! user ) {
10+ return < Redirect to = "/" /> ;
1111 }
1212
1313 return children ;
Original file line number Diff line number Diff line change @@ -122,3 +122,7 @@ export const signInWithGoogle = () => {
122122 provider . setCustomParameters ( { prompt : 'select_account' } ) ;
123123 return firebase . auth ( ) . signInWithPopup ( provider ) ;
124124} ;
125+
126+ export const getLoggedUser = ( ) => {
127+ return JSON . parse ( localStorage . getItem ( 'causefolioUser' ) ) ;
128+ } ;
You can’t perform that action at this time.
0 commit comments