File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import AuthenticationPage, {
17
17
action as authAction ,
18
18
} from './pages/Authentication' ;
19
19
import { action as logoutAction } from './pages/Logout' ;
20
- import { tokenLoader } from './util/auth' ;
20
+ import { checkAuthLoader , tokenLoader } from './util/auth' ;
21
21
22
22
const router = createBrowserRouter ( [
23
23
{
@@ -56,13 +56,15 @@ const router = createBrowserRouter([
56
56
path : 'edit' ,
57
57
element : < EditEventPage /> ,
58
58
action : manipulateEventAction ,
59
+ loader : checkAuthLoader ,
59
60
} ,
60
61
] ,
61
62
} ,
62
63
{
63
64
path : 'new' ,
64
65
element : < NewEventPage /> ,
65
66
action : manipulateEventAction ,
67
+ loader : checkAuthLoader ,
66
68
} ,
67
69
] ,
68
70
} ,
Original file line number Diff line number Diff line change
1
+ import { redirect } from 'react-router-dom' ;
2
+
1
3
export function getAuthToken ( ) {
2
4
const token = localStorage . getItem ( 'token' ) ;
3
5
return token ;
@@ -6,3 +8,13 @@ export function getAuthToken() {
6
8
export function tokenLoader ( ) {
7
9
return getAuthToken ( ) ;
8
10
}
11
+
12
+ export function checkAuthLoader ( ) {
13
+ const token = getAuthToken ( ) ;
14
+
15
+ if ( ! token ) {
16
+ return redirect ( '/auth' ) ;
17
+ }
18
+
19
+ return null ;
20
+ }
You can’t perform that action at this time.
0 commit comments