🤍 전 강의 25% 할인 중 🤍

2024년 상반기를 돌아보고 하반기에도 함께 성장해요!
인프런이 준비한 25% 할인 받으러 가기 >>

  • 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

로그인이 안됩니다.

22.02.22 12:29 작성 조회수 263

0

Redux-saga 강의 듣던중 로그인1초후에 된다고 강의중에 말씀하시는데 저는 아예 로그인이 안됩니다. 콘솔창 올립니다. 어디부터 손을 대야하는걸까요??

답변 5

·

답변을 작성해보세요.

1

import { createWrapper } from 'next-redux-wrapper';
import { applyMiddleware, compose, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import createSagaMiddleware from 'redux-saga';

import reducer from '../reducers'

const loggerMiddleware = ({ dispatch, getState }) => (next) => (action) => {
  console.log(action);
  return next(action);
};


const configureStore = () => {
  const sagaMiddleware = createSagaMiddleware();
  const middlewares = [sagaMiddleware, loggerMiddleware];
  const enhancer = process.env.NODE_ENV === 'production'
    ? compose(applyMiddleware(...middlewares))                      // 배포용일때 Devtool연결 안해놓고
    : composeWithDevTools(applyMiddleware(...middlewares))              // 개발용일때 Devtools 연결, (history가 다 보이면 보안에 취약, 메모리부하)
  const store = createStore(reducer, enhancer);
  return store;
};

const wrapper = createWrapper(configureStore, {
  debug: process.env.NODE_ENV === 'development',
});

export default wrapper;
 

0

 

0

prepare\front\saga\user.js 올려드렸습니다~

saga login 콘솔이 안 찍히는걸로 봐서는 사가 연결이 제대로 안 된 것 같습니다. store/configureStore.js 올려주세요.

0

Warning: MenuItem should not leave underfined `key`. 라는 붉은색 경고 메시지가 콘솔창에 나옵니다. 위치는 next-dev.js?3515:32 라고 나옵니다.

이 부분은 다른 문제라서 공지사항(새소식) 참고해주세요~

0

saga 로그인 부분 코드 전체 올려주세요.

import { all, fork, delay, put, takeLatest } from 'redux-saga/effects';
import axios from 'axios';
import { LOG_IN_REQUEST, LOG_IN_SUCCESS, LOG_IN_FAILURE,
        LOG_OUT_REQUEST, LOG_OUT_SUCCESS, LOG_OUT_FAILURE,
        SIGN_UP_REQUEST, SIGN_UP_SUCCESS, SIGN_UP_FAILURE,
} from '../reducers/user';

function logInAPI(data) {
  return axios.post('/api/login', data)
}

function* logIn(action) {
  try{
    console.log('saga logIn');
    // const result = yield call(logInAPI, action.data);
    yield delay(1000);
    yield put({
      type: LOG_IN_SUCCESS,
      data: action.data,
    });
  } catch (err) {
    yield put({
      type: LOG_IN_FAILURE,
      error: err.response.data,
    })
  }
}

function logOutAPI() {
  return axios.post('/api/login')
}

function* logOut() {
  try{
    // const result = yield call(logOutAPI);
    yield delay(1000);
    yield put({
      type: LOG_OUT_SUCCESS,
      data: result.data
    });
  } catch (err) {
    yield put({
      type: LOG_OUT_FAILURE,
      error: err.response.data,
    })
  }
}

function signUpAPI() {
  return axios.post('/api/login')
}

function* signUp() {
  try{
    // const result = yield call(signUpAPI);
    yield delay(1000);
    yield put({
      type: SIGN_UP_SUCCESS,

    });
  } catch (err) {
    yield put({
      type: SIGN_UP_FAILURE,
      error: err.response.data,
    })
  }
}

function* watchLogIn() {
  yield takeLatest(LOG_IN_REQUEST, logIn);
}

function* watchLogOut() {
  yield takeLatest(LOG_OUT_REQUEST, logOut);
}

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

export default function* userSaga() {
  yield all([
    fork(watchLogIn),
    fork(watchLogOut),
    fork(watchSignUp),
  ])
}
채널톡 아이콘