210320_ TIL / 회원가입

김승훈·2021년 4월 16일
0

flow-clone_TIL

목록 보기
4/12

오늘 할 일

  1. 회원가입 리듀서 작업
  2. 회원가입 redux-saga 작업

** axios 로 회원가입 데이터를 보냈지만 ... cors에러로 해결 하지 못함 상용님이 원격으로 봐주신다고 합니다.

import axios from 'axios';
import { all, fork, put, call, takeLatest } from "redux-saga/effects";
import { SIGN_UP_REQUEST, SIGN_UP_SUCCESS, SIGN_UP_FAILURE } from '../reducers/user';

function signUpAPI(data) {
  return axios.post('/signup', data);
}

function* signUp(action) {
  try {
    const result = yield call(signUpAPI, action.data);
    console.log(result);
    yield put({
      type: SIGN_UP_SUCCESS,
    });
  } catch (err) {
    console.log(err)
    yield put({
      type: SIGN_UP_FAILURE,
      error: err.response.data,
    });
  }
}

function* watchSignUp() {
  yield takeLatest(SIGN_UP_REQUEST, signUp);
}

export default function* userSaga() {
  yield all([
    fork(watchSignUp)
  ]);
}

내일 할일

프로젝트 화면 홈,

사이드 메뉴 만들기

0개의 댓글