Created
October 11, 2017 09:54
-
-
Save divyanshu013/cb09d40866865c50e11745c4289b8809 to your computer and use it in GitHub Desktop.
Final index.js file with routes and handleAuthentication for TodoMVC Auth Client
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 characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Route, Router } from 'react-router-dom'; | |
import TodoModel from './todoModel'; | |
import TodoApp from './todoApp'; | |
import Callback from './Callback'; | |
import Auth from './auth'; | |
import history from './history'; | |
const auth = new Auth(); | |
const handleAuthentication = (nextState, replace) => { | |
if (/access_token|id_token|error/.test(nextState.location.hash)) { | |
auth.handleAuthentication(); | |
} | |
} | |
let model = new TodoModel('react-todos'); | |
let render = () => { | |
ReactDOM.render( | |
<Router history={history} component={TodoApp}> | |
<div> | |
<Route path="/" render={(props) => <TodoApp model={model} auth={auth} {...props} />} /> | |
<Route path="/callback" render={(props) => { | |
handleAuthentication(props); | |
return <Callback {...props} /> | |
}} | |
/> | |
</div> | |
</Router>, | |
document.getElementsByClassName('todoapp')[0] | |
) | |
}; | |
model.subscribe(render); | |
render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment