Fixed persistent loading of user and team
This commit is contained in:
@@ -3,15 +3,12 @@ import { replace } from 'react-router-redux';
|
|||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import auth from 'utils/auth';
|
import auth from 'utils/auth';
|
||||||
|
|
||||||
import { updateUser } from './UserActions';
|
|
||||||
import { updateTeam } from './TeamActions';
|
|
||||||
|
|
||||||
export const SLACK_AUTH_PENDING = 'SLACK_AUTH_PENDING';
|
export const SLACK_AUTH_PENDING = 'SLACK_AUTH_PENDING';
|
||||||
export const SLACK_AUTH_SUCCESS = 'SLACK_AUTH_SUCCESS';
|
export const SLACK_AUTH_SUCCESS = 'SLACK_AUTH_SUCCESS';
|
||||||
export const SLACK_AUTH_FAILURE = 'SLACK_AUTH_FAILURE';
|
export const SLACK_AUTH_FAILURE = 'SLACK_AUTH_FAILURE';
|
||||||
|
|
||||||
const slackAuthPending = makeActionCreator(SLACK_AUTH_PENDING);
|
const slackAuthPending = makeActionCreator(SLACK_AUTH_PENDING);
|
||||||
const slackAuthSuccess = makeActionCreator(SLACK_AUTH_SUCCESS, 'user');
|
const slackAuthSuccess = makeActionCreator(SLACK_AUTH_SUCCESS, 'user', 'team');
|
||||||
const slackAuthFailure = makeActionCreator(SLACK_AUTH_FAILURE, 'error');
|
const slackAuthFailure = makeActionCreator(SLACK_AUTH_FAILURE, 'error');
|
||||||
|
|
||||||
export function slackAuthAsync(code) {
|
export function slackAuthAsync(code) {
|
||||||
@@ -23,12 +20,11 @@ export function slackAuthAsync(code) {
|
|||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
auth.setToken(data.data.accessToken);
|
auth.setToken(data.data.accessToken);
|
||||||
dispatch(updateUser(data.data.user));
|
dispatch(slackAuthSuccess(data.data.user, data.data.team));
|
||||||
dispatch(updateTeam(data.data.team));
|
|
||||||
dispatch(replace('/dashboard'));
|
dispatch(replace('/dashboard'));
|
||||||
})
|
})
|
||||||
// .catch((err) => {
|
.catch((err) => {
|
||||||
// dispatch(push('/error'));
|
dispatch(push('/error'));
|
||||||
// })
|
})
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
41
src/index.js
41
src/index.js
@@ -35,7 +35,32 @@ const store = createStore(reducer, applyMiddleware(
|
|||||||
routerMiddlewareWithHistory,
|
routerMiddlewareWithHistory,
|
||||||
loggerMiddleware,
|
loggerMiddleware,
|
||||||
), autoRehydrate());
|
), autoRehydrate());
|
||||||
persistStore(store);
|
|
||||||
|
persistStore(store, {
|
||||||
|
whitelist: [
|
||||||
|
'user',
|
||||||
|
'team',
|
||||||
|
]
|
||||||
|
}, () => {
|
||||||
|
render((
|
||||||
|
<Provider store={store}>
|
||||||
|
<Router history={History}>
|
||||||
|
<Route path="/">
|
||||||
|
<IndexRoute component={Home} />
|
||||||
|
|
||||||
|
<Route path="/dashboard" component={Dashboard
|
||||||
|
} onEnter={ requireAuth } />
|
||||||
|
<Route path="/atlas/:id" component={Dashboard} onEnter={ requireAuth } />
|
||||||
|
<Route path="/atlas/:id/new" component={Dashboard} onEnter={ requireAuth } />
|
||||||
|
|
||||||
|
<Route path="/editor" component={Dashboard} />
|
||||||
|
|
||||||
|
<Route path="/auth/slack" component={SlackAuth} />
|
||||||
|
</Route>
|
||||||
|
</Router>
|
||||||
|
</Provider>
|
||||||
|
), document.getElementById('root'));
|
||||||
|
});
|
||||||
|
|
||||||
function requireAuth(nextState, replace) {
|
function requireAuth(nextState, replace) {
|
||||||
if (!auth.loggedIn()) {
|
if (!auth.loggedIn()) {
|
||||||
@@ -46,17 +71,3 @@ function requireAuth(nextState, replace) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render((
|
|
||||||
<Provider store={store}>
|
|
||||||
<Router history={History}>
|
|
||||||
<Route path="/">
|
|
||||||
<IndexRoute component={Home} />
|
|
||||||
|
|
||||||
<Route path="/dashboard" component={Dashboard} onEnter={ requireAuth } />
|
|
||||||
<Route path="/editor" component={App} />
|
|
||||||
|
|
||||||
<Route path="/auth/slack" component={SlackAuth} />
|
|
||||||
</Route>
|
|
||||||
</Router>
|
|
||||||
</Provider>
|
|
||||||
), document.getElementById('root'));
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { UPDATE_TEAM } from 'actions/TeamActions';
|
import { SLACK_AUTH_SUCCESS } from 'actions/SlackAuthAction';
|
||||||
|
|
||||||
const team = (state = null, action) => {
|
const team = (state = null, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case UPDATE_TEAM: {
|
case SLACK_AUTH_SUCCESS: {
|
||||||
return {
|
return {
|
||||||
...action.team,
|
...action.team,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { UPDATE_USER } from 'actions/UserActions';
|
import { SLACK_AUTH_SUCCESS } from 'actions/SlackAuthAction';
|
||||||
|
|
||||||
const user = (state = null, action) => {
|
const user = (state = null, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case UPDATE_USER: {
|
case SLACK_AUTH_SUCCESS: {
|
||||||
return {
|
return {
|
||||||
...action.user,
|
...action.user,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class SlackAuth extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>Loading...</div>
|
<div></div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user