Skip to content

Instantly share code, notes, and snippets.

@divyanshu013
Created October 11, 2017 09:54
Show Gist options
  • Save divyanshu013/cb09d40866865c50e11745c4289b8809 to your computer and use it in GitHub Desktop.
Save divyanshu013/cb09d40866865c50e11745c4289b8809 to your computer and use it in GitHub Desktop.
Final index.js file with routes and handleAuthentication for TodoMVC Auth Client
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