actionRegister.js 792 B

12345678910111213141516171819202122232425262728
  1. import { gql } from "../helpers";
  2. import { actionPromise } from "../reducers";
  3. import { actionLogin } from "./actionLogin";
  4. export const actionRegister = (username, password) => async (dispatch, getState) => {
  5. await dispatch(
  6. actionPromise(
  7. "register",
  8. gql(
  9. `mutation register($username:String,$password:String){
  10. UserUpsert(user:{username:$username,password:$password}){
  11. _id username
  12. }
  13. }`,
  14. {
  15. username,
  16. password,
  17. }
  18. )
  19. )
  20. );
  21. const {
  22. promise: { register },
  23. } = getState();
  24. if (register.status === "FULFILLED") {
  25. dispatch(actionLogin(username, password));
  26. }
  27. };