accounts-frontend/src/routes.js

54 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Route, IndexRoute } from 'react-router';
2016-01-04 02:48:42 +05:30
import RootPage from 'pages/root/RootPage';
import IndexPage from 'pages/index/IndexPage';
import AuthPage from 'pages/auth/AuthPage';
2016-03-02 02:06:14 +05:30
import { authenticate } from 'components/user/actions';
2016-02-26 11:55:47 +05:30
2016-02-23 11:27:16 +05:30
import OAuthInit from 'components/auth/OAuthInit';
import Register from 'components/auth/Register';
import Login from 'components/auth/Login';
import Permissions from 'components/auth/Permissions';
import Activation from 'components/auth/Activation';
import Password from 'components/auth/Password';
import Logout from 'components/auth/Logout';
import PasswordChange from 'components/auth/PasswordChange';
import ForgotPassword from 'components/auth/ForgotPassword';
2016-03-02 02:06:14 +05:30
import authFlow from 'services/authFlow';
2016-03-02 02:06:14 +05:30
export default function routesFactory(store) {
2016-02-26 11:55:47 +05:30
const state = store.getState();
if (state.user.token) {
// authorizing user if it is possible
store.dispatch(authenticate(state.user.token));
2016-02-26 11:55:47 +05:30
}
2016-03-02 02:06:14 +05:30
authFlow.setStore(store);
const onEnter = {
onEnter: ({location}, replace) => authFlow.handleRequest(location.pathname, replace)
};
return (
<Route path="/" component={RootPage}>
2016-03-02 02:06:14 +05:30
<IndexRoute component={IndexPage} />
<Route path="oauth" component={OAuthInit} {...onEnter} />
<Route path="logout" component={Logout} {...onEnter} />
<Route path="auth" component={AuthPage}>
2016-03-02 02:06:14 +05:30
<Route path="/login" components={new Login()} {...onEnter} />
<Route path="/password" components={new Password()} {...onEnter} />
<Route path="/register" components={new Register()} {...onEnter} />
<Route path="/activation" components={new Activation()} {...onEnter} />
<Route path="/oauth/permissions" components={new Permissions()} {...onEnter} />
<Route path="/password-change" components={new PasswordChange()} {...onEnter} />
<Route path="/forgot-password" components={new ForgotPassword()} {...onEnter} />
</Route>
</Route>
);
}