Skip to content

Instantly share code, notes, and snippets.

@sebastiandeutsch
Created January 8, 2017 01:45
Show Gist options
  • Save sebastiandeutsch/103f2205a42469ef7da439d3f348de42 to your computer and use it in GitHub Desktop.
Save sebastiandeutsch/103f2205a42469ef7da439d3f348de42 to your computer and use it in GitHub Desktop.
Redux example action using a concrete API (injected as paramter to be mocked in testing).
export function postAuthorization(email, password, Api = AuthenticationApi) {
return (dispatch) => {
return Api.postAuthorization(email, password).then(
(response) => {
const token = response.data.token;
localStorage.setItem(`TeamReaderApp_${process.env.NODE_ENV}_token`, token);
dispatch(createSession(token));
dispatch(setLinks({ collection: response.data.links }));
dispatch(loadCategories());
return response;
},
(error) => {
dispatch({
type: CREATE_SESSION,
payload: error,
error: true
});
throw error;
}
);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment