acklen-keystone
Version:
Web Application Framework and Admin GUI / Content Management System built on Express.js and Mongoose
74 lines (65 loc) • 2.08 kB
JavaScript
/**
* This is the main entry file, which we compile the main JS bundle from. It
* only contains the client side routing setup.
*/
// Needed for ES6 generators (redux-saga) to work
import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
import { Provider } from 'react-redux';
import { syncHistoryWithStore } from 'react-router-redux';
import Auth0 from 'auth0-js';
import App from './App';
import Home from './screens/Home';
import Item from './screens/Item';
import List from './screens/List';
import store from './store';
// Sync the browser history to the Redux store
const history = syncHistoryWithStore(browserHistory, store);
// Initialise Keystone.User list
import { listsByKey } from '../utils/lists';
Keystone.User = listsByKey[Keystone.userList];
var webAuth = new Auth0.WebAuth({
domain: Keystone.auth0DomainUrl,
clientID: Keystone.auth0ClientId,
responseType: 'token id_token',
scope: 'openid',
});
const requireAuth = (nextState, replace, callback) => {
webAuth.checkSession({
redirectUri: window.location.origin,
}, (errRenew, authResult) => {
if (authResult && authResult.accessToken) {
callback();
} else {
window.location = '/keystone/signout';
}
});
};
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route
onEnter={(nextState, replace, callback) =>
{ requireAuth(nextState, replace, callback); }}
path={Keystone.adminPath}
component={App}>
<IndexRoute
onEnter={(nextState, replace, callback) =>
{ requireAuth(nextState, replace, callback); }}
component={Home} />
<Route
onEnter={(nextState, replace,
callback) =>
{ requireAuth(nextState, replace, callback); }}
path=":listId" component={List} />
<Route
onEnter={(nextState, replace, callback) =>
{ requireAuth(nextState, replace, callback); }}
path=":listId/:itemId" component={Item} />
</Route>
</Router>
</Provider>,
document.getElementById('react-root')
);