Skip to content

Instantly share code, notes, and snippets.

@himanshu-dixit
Created December 15, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himanshu-dixit/3a7d16550c0d16fd9aa842e5446fbc2e to your computer and use it in GitHub Desktop.
Save himanshu-dixit/3a7d16550c0d16fd9aa842e5446fbc2e to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
...
class App extends Component {
render() {
const handleAuthentication = (nextState, replace) => {
if (/access_token|id_token|error/.test(nextState.location.hash)) {
const auth = new Auth();
auth.handleAuthentication();
}
}
// If user logged in, redirect to dashboard.
if(localStorage.getItem('isLoggedIn')==='true'){
history.replace('/dashboard');
}
return (
<div className="container">
<Router history={history}>
<div>
<Route exact path="/" render={(props) => <Login />} />
<Route exact path="/dashboard" render={(props) => <Dashboard/>} />
<Route path="/callback" render={(props) => {
handleAuthentication(props);
return <div>loading</div>;
}}></Route>
</div>
</Router>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment