리엑트 블로그 만들기 6 - Login Modal 만들기 1

리엑트 블로그 만들기 6 - Login Modal 만들기 1

import { all, put } from "@redux-saga/core/effects";
import axios from "axios";
import { takeEvery } from "redux-saga";
import { call, fork } from "redux-saga/effects";
import { LOGIN_FAILURE, LOGIN_REQUEST, LOGIN_SUCCESS } from "../types";

const loginUserAPI = (loginData) => {
console.log(loginData, "loginData");
const config = {
headers: {
"Content-Type": "application/json",
},
};

return axios.post("api/auth", loginData, config);
};

function* loginUser(action) {
try {
const result = yield call(loginUserAPI, action.payload);
console.log(result);
yield put({
ytpe: LOGIN_SUCCESS,
payload: result.data,
});
} catch (e) {
yield put({
type: LOGIN_FAILURE,
payload: e.response,
});
}
}

function* watchLoginUser() {
yield takeEvery(LOGIN_REQUEST, loginUser);
}


export default function* authSaga(){
yield all([
fork(watchLoginUser)
])
}
Share