mirror of
https://github.com/wassname/talk.git
synced 2026-07-02 14:32:55 +08:00
Updating store to include auth and apollo.
This commit is contained in:
@@ -20,17 +20,20 @@ export const cleanState = () => ({type: actions.CLEAN_STATE});
|
||||
// Sign In Actions
|
||||
|
||||
const signInRequest = () => ({type: actions.FETCH_SIGNIN_REQUEST});
|
||||
const signInSuccess = (user, isAdmin) => ({type: actions.FETCH_SIGNIN_SUCCESS, user, isAdmin});
|
||||
|
||||
// const signInSuccess = (user, isAdmin) => ({type: actions.FETCH_SIGNIN_SUCCESS, user, isAdmin});
|
||||
const signInFailure = error => ({type: actions.FETCH_SIGNIN_FAILURE, error});
|
||||
|
||||
export const fetchSignIn = (formData) => (dispatch) => {
|
||||
dispatch(signInRequest());
|
||||
coralApi('/auth/local', {method: 'POST', body: formData})
|
||||
.then(({user}) => {
|
||||
const isAdmin = !!user.roles.filter(i => i === 'admin').length;
|
||||
dispatch(signInSuccess(user, isAdmin));
|
||||
.then(() => {
|
||||
|
||||
// const isAdmin = !!user.roles.filter(i => i === 'admin').length;
|
||||
// dispatch(signInSuccess(user, isAdmin));
|
||||
dispatch(hideSignInDialog());
|
||||
dispatch(addItem(user, 'users'));
|
||||
|
||||
// dispatch(addItem(user, 'users'));
|
||||
})
|
||||
.catch(() => dispatch(signInFailure(lang.t('error.emailPasswordError'))));
|
||||
};
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import {createStore, applyMiddleware, compose} from 'redux';
|
||||
import {createStore, combineReducers, applyMiddleware, compose} from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import mainReducer from './reducers';
|
||||
import authReducer from './reducers/auth';
|
||||
import {client} from './client';
|
||||
|
||||
export default createStore(
|
||||
client.reducer(),
|
||||
mainReducer,
|
||||
combineReducers({
|
||||
auth: authReducer,
|
||||
apollo: client.reducer()
|
||||
}),
|
||||
{},
|
||||
compose(
|
||||
window.devToolsExtension && window.devToolsExtension(),
|
||||
applyMiddleware(thunk)
|
||||
|
||||
Reference in New Issue
Block a user