Browse Source

logout redux 초기화

feature/auth
김장현 2 years ago
parent
commit
027d2aa041
  1. 107
      src/modules/account/login/sagas/authSaga.ts
  2. 18
      src/redux/reducers/rootReducer.ts

107
src/modules/account/login/sagas/authSaga.ts

@ -25,7 +25,7 @@ import { Console } from 'console';
function* userLoginSaga(action: ActionType<typeof Actions.login.request>) { function* userLoginSaga(action: ActionType<typeof Actions.login.request>) {
const param = action.payload; const param = action.payload;
try { try {
// console.log('=-==================='); // console.log('=-===================');
const { data, errorCode } = yield call(authAPI.usersLogin, param); const { data, errorCode } = yield call(authAPI.usersLogin, param);
//console.log('>>>>>11>>>>>>>', data); //console.log('>>>>>11>>>>>>>', data);
@ -119,20 +119,19 @@ function* userLogoutSaga() {
try { try {
if (accessToken) { if (accessToken) {
// console.log('dddddddddddddddddddddddddddddddddddd'); // console.log('dddddddddddddddddddddddddddddddddddd');
const decodedToken = decode<LoginData>(accessToken); const decodedToken = decode<LoginData>(accessToken);
const res = yield call(authAPI.usersLogout, decodedToken.cstmrSno); const res = yield call(authAPI.usersLogout, decodedToken.cstmrSno);
console.log("res>>>>>>>>",res); console.log('res>>>>>>>>', res);
if(res.data=="SUCCESS"){ // if(res.data=="SUCCESS"){
location.reload(); // location.reload();
} // }
} }
yield put(Actions.logout.success()); yield put(Actions.logout.success());
cookieStorage.removeCookie(COOKIE_ACCESS_TOKEN); cookieStorage.removeCookie(COOKIE_ACCESS_TOKEN);
cookieStorage.removeCookie(COOKIE_REFRESH_TOKEN); cookieStorage.removeCookie(COOKIE_REFRESH_TOKEN);
yield put(replace('/')); yield put(replace('/'));
} catch (error) { } catch (error) {
yield put(Actions.logout.failure(error)); yield put(Actions.logout.failure(error));
} }
@ -141,11 +140,11 @@ function* userLogoutSaga() {
function* userPageSaga( function* userPageSaga(
action: ActionType<typeof Actions.userPageAction.request> action: ActionType<typeof Actions.userPageAction.request>
) { ) {
try{ try {
const controlId = action.payload; const controlId = action.payload;
const { data } = yield call(authAPI.getUserPage, controlId); const { data } = yield call(authAPI.getUserPage, controlId);
// console.log('userPageData : ', data) // console.log('userPageData : ', data)
yield put(Actions.userPageAction.success(data)); yield put(Actions.userPageAction.success(data));
} catch (error) { } catch (error) {
yield put(Actions.userPageAction.failure(error)); yield put(Actions.userPageAction.failure(error));
@ -153,80 +152,80 @@ function* userPageSaga(
} }
function* userUpdateSaga( function* userUpdateSaga(
action: ActionType<typeof Actions.userupdateAction.request>) { action: ActionType<typeof Actions.userupdateAction.request>
) {
const param = action.payload; const param = action.payload;
try{ try {
const { data,errorCode } = yield call(authAPI.updateUser, param); const { data, errorCode } = yield call(authAPI.updateUser, param);
yield put(Actions.pwUpdateAction.success(data)); yield put(Actions.pwUpdateAction.success(data));
if (data.errorCode==='-1') { if (data.errorCode === '-1') {
yield put( yield put(
MessageActions.IS_ERROR({ MessageActions.IS_ERROR({
errorCode: ERROR_MESSAGE.code, errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message, errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false, isHistoryBack: false,
isRefresh: false isRefresh: false
}) })
); );
} } else {
else{
yield put( yield put(
MessageActions.IS_MESSAGE({ MessageActions.IS_MESSAGE({
messageCode: SAVE_MESSAGE.code, messageCode: SAVE_MESSAGE.code,
message: SAVE_MESSAGE.message, message: SAVE_MESSAGE.message,
isHistoryBack: false, isHistoryBack: false,
isRefresh: true isRefresh: true
}) })
); );
} }
} catch (error) { } catch (error) {
yield put( yield put(
MessageActions.IS_ERROR({ MessageActions.IS_ERROR({
errorCode: ERROR_MESSAGE.code, errorCode: ERROR_MESSAGE.code,
errorMessage: '처리 중 에러입니다.', errorMessage: '처리 중 에러입니다.',
isHistoryBack: false, isHistoryBack: false,
isRefresh: false isRefresh: false
}) })
); );
}
} }
}
function* userPwSaga( function* userPwSaga(
action: ActionType<typeof Actions.pwUpdateAction.request>) { action: ActionType<typeof Actions.pwUpdateAction.request>
) {
const param = action.payload; const param = action.payload;
try{ try {
const { data,errorCode } = yield call(authAPI.pwupdate, param); const { data, errorCode } = yield call(authAPI.pwupdate, param);
//yield put(Actions.pwUpdateAction.success(data)); //yield put(Actions.pwUpdateAction.success(data));
// console.log("saaa",data); // console.log("saaa",data);
if (data.errorCode==='-1') { if (data.errorCode === '-1') {
yield put( yield put(
MessageActions.IS_ERROR({ MessageActions.IS_ERROR({
errorCode: ERROR_MESSAGE.code, errorCode: ERROR_MESSAGE.code,
errorMessage: ERROR_MESSAGE.message, errorMessage: ERROR_MESSAGE.message,
isHistoryBack: false, isHistoryBack: false,
isRefresh: false isRefresh: false
}) })
); );
} } else {
else{
yield put( yield put(
MessageActions.IS_MESSAGE({ MessageActions.IS_MESSAGE({
messageCode: SAVE_MESSAGE.code, messageCode: SAVE_MESSAGE.code,
message: SAVE_MESSAGE.message, message: SAVE_MESSAGE.message,
isHistoryBack: true, isHistoryBack: true,
isRefresh: true isRefresh: true
}) })
); );
} }
} catch (error) { } catch (error) {
yield put( yield put(
MessageActions.IS_ERROR({ MessageActions.IS_ERROR({
errorCode: ERROR_MESSAGE.code, errorCode: ERROR_MESSAGE.code,
errorMessage: '비밀번호를 확인해주세요', errorMessage: '비밀번호를 확인해주세요',
isHistoryBack: false, isHistoryBack: false,
isRefresh: false isRefresh: false
}) })
); );
}
} }
}
// function* updateSaga(action: ActionType<typeof Actions.userupdateAction.request>) { // function* updateSaga(action: ActionType<typeof Actions.userupdateAction.request>) {
// try { // try {
// const detail = action.payload; // const detail = action.payload;

18
src/redux/reducers/rootReducer.ts

@ -14,7 +14,10 @@ import { dronSaga } from '../../modules/basis/dron/sagas/basisDronSaga';
import { groupReducer } from '../../modules/basis/group/reducers/basisGroupReducer'; import { groupReducer } from '../../modules/basis/group/reducers/basisGroupReducer';
import { basGroupSaga } from '../../modules/basis/group/sagas/basisGroupSaga'; import { basGroupSaga } from '../../modules/basis/group/sagas/basisGroupSaga';
import { messageReducer } from '../../modules/comn/message/reducers/comnMessageReducer'; import { messageReducer } from '../../modules/comn/message/reducers/comnMessageReducer';
import { mypageReducer, userPwReducer } from '../../modules/account/login/reducers/authReducer'; import {
mypageReducer,
userPwReducer
} from '../../modules/account/login/reducers/authReducer';
import { findSaga } from '../../modules/account/find/sagas/findSaga'; import { findSaga } from '../../modules/account/find/sagas/findSaga';
import { findAccountReducer } from '../../modules/account/find/reducers/findReducer'; import { findAccountReducer } from '../../modules/account/find/reducers/findReducer';
@ -26,7 +29,7 @@ import {
controlGpFltPlanReducer, controlGpFltPlanReducer,
controlGpSaga, controlGpSaga,
ControlGpState, ControlGpState,
controlGpLogReducer, controlGpLogReducer
} from '../../modules/control/gp'; } from '../../modules/control/gp';
import controlMapReducer from '../../modules/control/map/reducers/controlMapReducer'; import controlMapReducer from '../../modules/control/map/reducers/controlMapReducer';
import { mainDahReducer } from '../../modules/main/dash/reducers/mainDashReducer'; import { mainDahReducer } from '../../modules/main/dash/reducers/mainDashReducer';
@ -57,7 +60,7 @@ export function* saga() {
yield all([fork(findSaga)]); yield all([fork(findSaga)]);
} }
const rootReducer = combineReducers({ const appReducer = combineReducers({
auth, auth,
navbar, navbar,
layout, layout,
@ -80,7 +83,14 @@ const rootReducer = combineReducers({
analysisHistoryState: analysisHistoryReducer, analysisHistoryState: analysisHistoryReducer,
analysisSimulatorState: analysisSimulatorReducer, analysisSimulatorState: analysisSimulatorReducer,
flightState: flightReducer, flightState: flightReducer,
findState: findAccountReducer, findState: findAccountReducer
}); });
const rootReducer = (state, action) => {
if (action.type === 'auth/USERS_LOGOUT_SUCCESS') {
appReducer(undefined, action);
}
return appReducer(state, action);
};
export default rootReducer; export default rootReducer;

Loading…
Cancel
Save