-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2660d74
commit 76fbd05
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/src/registerServiceWorker.js | ||
/src/apollo.js | ||
/src/shared/util/createFileLink.js | ||
/src/shared/util/privateRoutes.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
const Dashboard = (props) => <div>Welcome to the dashboard a private route.</div>; | ||
|
||
export default Dashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { Route, Redirect } from 'react-router-dom'; | ||
import decode from 'jwt-decode'; | ||
|
||
// TODO: Fix Eslint errors with this file, right now it's disabled on this file. | ||
|
||
const isAuthenticated = () => { | ||
const token = localStorage.getItem('token'); | ||
const refreshToken = localStorage.getItem('refreshToken'); | ||
try { | ||
decode(token); | ||
decode(refreshToken); | ||
} catch (err) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
const PrivateRoute = ({ component: Component, ...rest }) => ( | ||
<Route | ||
{...rest} | ||
render={(props) => | ||
isAuthenticated() ? ( | ||
<Component {...props} /> | ||
) : ( | ||
<Redirect | ||
to={{ | ||
pathname: '/login', | ||
}} | ||
/> | ||
) | ||
} | ||
/> | ||
); | ||
|
||
export default PrivateRoute; |