Last active
June 8, 2017 01:28
-
-
Save carlqt/6e4926d250d9e185e9f67a6ce804ca01 to your computer and use it in GitHub Desktop.
Revisions
-
carlqt revised this gist
Jun 8, 2017 . No changes.There are no files selected for viewing
-
carlqt revised this gist
Jun 8, 2017 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ //AuthRoute.js snippet import React from 'react'; import { Route, Redirect } from 'react-router-dom'; @@ -29,4 +28,4 @@ class AuthRoute extends React.Component { } } export default AuthRoute; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,3 +22,4 @@ export default () => ( </AuthRoute> </Switch> ) -
carlqt revised this gist
Jun 8, 2017 . 2 changed files with 24 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,3 @@ //AuthRoute.js snippet import React from 'react'; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import { Route, Switch } from 'react-router-dom'; import React from 'react'; import Property from './Property/Property'; import Upload from './Upload/Index'; import Cards from './Cards/Cards'; import AgentSignIn from './Agent/SignIn/SignIn'; import Protected from './Agent/Protected'; import SuperProtected from './Agent/superprotected'; import AuthRoute from './hoc/AuthRoute'; export default () => ( <Switch> <Route exact path="/" component={Cards} /> <Route exact path="/property/:name" component={Property} /> <Route exact path="/property_upload" component={Upload} /> <Route exact path="/agent/sign_in" component={AgentSignIn} /> {/*<Route exact path="/agent/protected" component={Protected} />*/} <AuthRoute back={"/agent/sign_in"}> <Route exact path="/agent/protected" component={Protected} /> <Route exact path="/agent/superprotected" component={SuperProtected} /> </AuthRoute> </Switch> ) -
carlqt created this gist
Jun 8, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ // Routes.js file snippet export default () => ( <Switch> <Route exact path="/" component={Cards} /> <Route exact path="/property/:name" component={Property} /> <Route exact path="/property_upload" component={Upload} /> <Route exact path="/agent/sign_in" component={AgentSignIn} /> {/*<Route exact path="/agent/protected" component={Protected} />*/} <AuthRoute back={"/agent/sign_in"}> <Route exact path="/agent/protected" component={Protected} /> <Route exact path="/agent/superprotected" component={SuperProtected} /> </AuthRoute> </Switch> ) ///////////////////////////////////////////////////////////////////////////// //AuthRoute.js snippet import React from 'react'; import { Route, Redirect } from 'react-router-dom'; class AuthRoute extends React.Component { constructor(props) { super(props); this.authenticated = this.authenticated.bind(this); } authenticated() { // Check for the token here // If token does not exists, return false // If token exists, check if it is also in the redux state // > if token is not in the redux state, validate token in the server // > If validation failed, return false else return true and store in redux state // If token exists in redux state as well, return true return false; } render() { return( <div> {this.authenticated() ? this.props.children : <Redirect to={this.props.back}/> } </div> ) } } export default AuthRoute;