mirror of
https://github.com/wassname/talk.git
synced 2026-08-16 11:29:31 +08:00
Enabling stream login with graphql.
This commit is contained in:
@@ -21,17 +21,17 @@ export const cleanState = () => ({type: actions.CLEAN_STATE});
|
||||
|
||||
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(() => {
|
||||
return coralApi('/auth/local', {method: 'POST', body: formData})
|
||||
.then((user) => {
|
||||
|
||||
// const isAdmin = !!user.roles.filter(i => i === 'admin').length;
|
||||
// dispatch(signInSuccess(user, isAdmin));
|
||||
dispatch(hideSignInDialog());
|
||||
const isAdmin = !!user.roles.filter(i => i === 'admin').length;
|
||||
dispatch(signInSuccess(user, isAdmin));
|
||||
// dispatch(hideSignInDialog());
|
||||
|
||||
// dispatch(addItem(user, 'users'));
|
||||
})
|
||||
@@ -78,7 +78,7 @@ const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error});
|
||||
export const fetchSignUp = formData => (dispatch) => {
|
||||
dispatch(signUpRequest());
|
||||
|
||||
coralApi('/users', {method: 'POST', body: formData})
|
||||
return coralApi('/users', {method: 'POST', body: formData})
|
||||
.then(({user}) => {
|
||||
dispatch(signUpSuccess(user));
|
||||
setTimeout(() =>{
|
||||
@@ -98,7 +98,7 @@ const forgotPassowordFailure = () => ({type: actions.FETCH_FORGOT_PASSWORD_FAILU
|
||||
|
||||
export const fetchForgotPassword = email => (dispatch) => {
|
||||
dispatch(forgotPassowordRequest(email));
|
||||
coralApi('/account/password/reset', {method: 'POST', body: {email}})
|
||||
return coralApi('/account/password/reset', {method: 'POST', body: {email}})
|
||||
.then(() => dispatch(forgotPassowordSuccess()))
|
||||
.catch(error => dispatch(forgotPassowordFailure(error)));
|
||||
};
|
||||
@@ -111,7 +111,7 @@ const logOutFailure = () => ({type: actions.LOGOUT_FAILURE});
|
||||
|
||||
export const logout = () => dispatch => {
|
||||
dispatch(logOutRequest());
|
||||
coralApi('/auth', {method: 'DELETE'})
|
||||
return coralApi('/auth', {method: 'DELETE'})
|
||||
.then(() => dispatch(logOutSuccess()))
|
||||
.catch(error => dispatch(logOutFailure(error)));
|
||||
};
|
||||
@@ -129,7 +129,7 @@ const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error});
|
||||
|
||||
export const checkLogin = () => dispatch => {
|
||||
dispatch(checkLoginRequest());
|
||||
coralApi('/auth')
|
||||
return coralApi('/auth')
|
||||
.then((result) => {
|
||||
if (!result.user) {
|
||||
throw new Error('Not logged in');
|
||||
|
||||
@@ -8,9 +8,15 @@ export default createStore(
|
||||
auth: authReducer,
|
||||
apollo: client.reducer()
|
||||
}),
|
||||
{},
|
||||
{
|
||||
apollo: {
|
||||
data: {
|
||||
loading: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
compose(
|
||||
window.devToolsExtension && window.devToolsExtension(),
|
||||
applyMiddleware(thunk)
|
||||
applyMiddleware(thunk),
|
||||
window.devToolsExtension && window.devToolsExtension()
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user