Browse Source

[Redux] /account/auth 수정

master
junh_eee(이준희) 8 months ago
parent
commit
5098b5b528
  1. 2
      src/@core/layouts/components/navbar/UserDropdown.js
  2. 2
      src/components/account/login/AccountLogin.js
  3. 2
      src/containers/analysis/simulator/AnalysisSimulationContainer.js
  4. 4
      src/modules/_sample/reducers/index.ts
  5. 38
      src/modules/account/auth/actions/index.ts
  6. 4
      src/modules/account/auth/apis/index.ts
  7. 14
      src/modules/account/auth/reducers/index.ts
  8. 24
      src/modules/account/auth/sagas/index.ts
  9. 2
      src/modules/utils/customAxiosUtil.ts
  10. 2
      src/views/control/main/ControlMain.js

2
src/@core/layouts/components/navbar/UserDropdown.js

@ -26,7 +26,7 @@ const UserDropdown = () => {
const { isLogin, user } = useSelector(state => state.authState); const { isLogin, user } = useSelector(state => state.authState);
const handelrLogout = async () => { const handelrLogout = async () => {
dispatch(Actions.userLogout.request()); dispatch(Actions.setLogout.request());
}; };
// useEffect(() => { // useEffect(() => {

2
src/components/account/login/AccountLogin.js

@ -68,7 +68,7 @@ export const AccountLogin = ({ props }) => {
return; return;
} }
dispatch(Actions.userLogin.request(loginForm)); dispatch(Actions.setLogin.request(loginForm));
}; };
// 로그인 실패 모달 // 로그인 실패 모달

2
src/containers/analysis/simulator/AnalysisSimulationContainer.js

@ -239,7 +239,7 @@ export const AnalysisSimulationContainer = props => {
// 로그아웃 // 로그아웃
const handlerLogout = () => { const handlerLogout = () => {
dispatch(AuthAction.userLogout.request()); dispatch(AuthAction.setLogout.request());
}; };
// 비행 시물레이션 데이터 닫기 // 비행 시물레이션 데이터 닫기

4
src/modules/_sample/reducers/index.ts

@ -1,14 +1,14 @@
import { createReducer } from 'typesafe-actions'; import { createReducer } from 'typesafe-actions';
import produce from 'immer'; import produce from 'immer';
import { SampleState, initSample } from '../models'; import { ISampleState, initSample } from '../models';
import * as Actions from '../actions'; import * as Actions from '../actions';
/** /**
* Reducer . * Reducer .
*/ */
export const sampleReducer = createReducer<SampleState, Actions.SampleActions>( export const sampleReducer = createReducer<ISampleState, Actions.SampleActions>(
initSample initSample
).handleAction(Actions.getDroneList.success, (state, action) => ).handleAction(Actions.getDroneList.success, (state, action) =>
produce(state, draft => {}) produce(state, draft => {})

38
src/modules/account/auth/actions/index.ts

@ -12,9 +12,9 @@ import {
} from '../models'; } from '../models';
// 로그인 // 로그인
const USER_LOGIN_REQUEST = 'auth/USER_LOGIN_REQUEST'; const SET_LOGIN_REQUEST = 'auth/SET_LOGIN_REQUEST';
const USER_LOGIN_SUCCESS = 'auth/USER_LOGIN_SUCCESS'; const SET_LOGIN_SUCCESS = 'auth/SET_LOGIN_SUCCESS';
const USER_LOGIN_FAILURE = 'auth/USER_LOGIN_FAILURE'; const SET_LOGIN_FAILURE = 'auth/SET_LOGIN_FAILURE';
// 인증 확인 // 인증 확인
const CHECK_AUTHENCATION_REQUEST = 'auth/CHECK_AUTHENCATION_REQUEST'; const CHECK_AUTHENCATION_REQUEST = 'auth/CHECK_AUTHENCATION_REQUEST';
@ -22,9 +22,9 @@ const CHECK_AUTHENCATION_SUCCESS = 'auth/CHECK_AUTHENCATION_SUCCESS';
const CHECK_AUTHENCATION_FAILURE = 'auth/CHECK_AUTHENCATION_FAILURE'; const CHECK_AUTHENCATION_FAILURE = 'auth/CHECK_AUTHENCATION_FAILURE';
// 로그아웃 // 로그아웃
const USER_LOGOUT_REQUEST = 'auth/USER_LOGOUT_REQUEST'; const SET_LOGOUT_REQUEST = 'auth/SET_LOGOUT_REQUEST';
const USER_LOGOUT_SUCCESS = 'auth/USER_LOGOUT_SUCCESS'; const SET_LOGOUT_SUCCESS = 'auth/SET_LOGOUT_SUCCESS';
const USER_LOGOUT_FAILURE = 'auth/USER_LOGOUT_FAILURE'; const SET_LOGOUT_FAILURE = 'auth/SET_LOGOUT_FAILURE';
// 마이페이지 조회 // 마이페이지 조회
const GET_USER_PAGE_REQUEST = 'auth/GET_USER_PAGE_REQUEST'; const GET_USER_PAGE_REQUEST = 'auth/GET_USER_PAGE_REQUEST';
@ -51,10 +51,10 @@ const UPDATE_USERPW_REQUEST = 'auth/UPDATE_USERPW_REQUEST';
const UPDATE_USERPW_SUCCESS = 'auth/UPDATE_USERPW_SUCCESS'; const UPDATE_USERPW_SUCCESS = 'auth/UPDATE_USERPW_SUCCESS';
const UPDATE_USERPW_FAILURE = 'auth/UPDATE_USERPW_FAILURE'; const UPDATE_USERPW_FAILURE = 'auth/UPDATE_USERPW_FAILURE';
export const userLogin = createAsyncAction( export const setLogin = createAsyncAction(
USER_LOGIN_REQUEST, SET_LOGIN_REQUEST,
USER_LOGIN_SUCCESS, SET_LOGIN_SUCCESS,
USER_LOGIN_FAILURE SET_LOGIN_FAILURE
)<UserAccount, UserData, string>(); )<UserAccount, UserData, string>();
export const check = createAsyncAction( export const check = createAsyncAction(
@ -63,17 +63,17 @@ export const check = createAsyncAction(
CHECK_AUTHENCATION_FAILURE CHECK_AUTHENCATION_FAILURE
)<void, { isLogin: boolean; user?: UserData }, AxiosError>(); )<void, { isLogin: boolean; user?: UserData }, AxiosError>();
export const userLogout = createAsyncAction( export const setLogout = createAsyncAction(
USER_LOGOUT_REQUEST, SET_LOGOUT_REQUEST,
USER_LOGOUT_SUCCESS, SET_LOGOUT_SUCCESS,
USER_LOGOUT_FAILURE SET_LOGOUT_FAILURE
)<void, void, AxiosError>(); )<void, void, AxiosError>();
// 사용안함? // 사용안함?
export const refresh = createAsyncAction( export const refresh = createAsyncAction(
USER_LOGOUT_REQUEST, SET_LOGOUT_REQUEST,
USER_LOGOUT_SUCCESS, SET_LOGOUT_SUCCESS,
USER_LOGOUT_FAILURE SET_LOGOUT_FAILURE
)<TokenAccount, UserData, AxiosError>(); )<TokenAccount, UserData, AxiosError>();
export const getUserPage = createAsyncAction( export const getUserPage = createAsyncAction(
@ -107,9 +107,9 @@ export const updateUserPw = createAsyncAction(
)<UpdatePwRq, UpdatePwRs, AxiosError>(); )<UpdatePwRq, UpdatePwRs, AxiosError>();
const actions = { const actions = {
userLogin, setLogin,
check, check,
userLogout, setLogout,
refresh, refresh,
updateUser, updateUser,
getUserPage, getUserPage,

4
src/modules/account/auth/apis/index.ts

@ -3,11 +3,11 @@ import { UserAccount, TokenAccount, UpdatePwRq, UpdateData } from '../models';
export const authAPI = { export const authAPI = {
// 로그인 // 로그인
usersLogin: async (data: UserAccount) => { setLogin: async (data: UserAccount) => {
return await axios.post('api/acnt/jwt/login', data); return await axios.post('api/acnt/jwt/login', data);
}, },
// 로그아웃 // 로그아웃
usersLogout: (id: number) => { setLogout: (id: number) => {
return axios.get(`api/acnt/jwt/logout/${id}`); return axios.get(`api/acnt/jwt/logout/${id}`);
}, },
// 토큰 재발급 // 토큰 재발급

14
src/modules/account/auth/reducers/index.ts

@ -4,17 +4,17 @@ import produce from 'immer';
import { createReducer } from 'typesafe-actions'; import { createReducer } from 'typesafe-actions';
// action // action
import * as Actions from '../actions';
// import { // import {
// AuthAction, // AuthAction,
// getUserPage, // getUserPage,
// check, // check,
// userLogin, // setLogin,
// userLogout, // setLogout,
// refresh, // refresh,
// deleteUser, // deleteUser,
// checkUserPw // checkUserPw
// } from '../actions'; // } from '../actions';
import * as Actions from '../actions';
import { import {
UserPageState, UserPageState,
@ -27,19 +27,19 @@ import {
export const authReducer = createReducer<AuthState, Actions.AuthAction>( export const authReducer = createReducer<AuthState, Actions.AuthAction>(
initAuth initAuth
) )
.handleAction(Actions.userLogin.success, (state, action) => .handleAction(Actions.setLogin.success, (state, action) =>
produce(state, draft => { produce(state, draft => {
draft.isLogin = true; draft.isLogin = true;
draft.user = action.payload; draft.user = action.payload;
}) })
) )
.handleAction(Actions.userLogin.request, (state, action) => .handleAction(Actions.setLogin.request, (state, action) =>
produce(state, draft => { produce(state, draft => {
draft.isLogin = false; draft.isLogin = false;
draft.message = ''; draft.message = '';
}) })
) )
.handleAction(Actions.userLogin.failure, (state, action) => .handleAction(Actions.setLogin.failure, (state, action) =>
produce(state, draft => { produce(state, draft => {
draft.isLogin = false; draft.isLogin = false;
draft.message = action.payload; draft.message = action.payload;
@ -63,7 +63,7 @@ export const authReducer = createReducer<AuthState, Actions.AuthAction>(
draft.user = action.payload; draft.user = action.payload;
}) })
) )
.handleAction(Actions.userLogout.success, state => .handleAction(Actions.setLogout.success, state =>
produce(state, draft => { produce(state, draft => {
draft.isLogin = false; draft.isLogin = false;
draft.user = undefined; draft.user = undefined;

24
src/modules/account/auth/sagas/index.ts

@ -16,10 +16,10 @@ import {
} from '../service/cookie'; } from '../service/cookie';
import * as MessageActions from '../../../comn/message/actions/comnMessageAction'; import * as MessageActions from '../../../comn/message/actions/comnMessageAction';
function* userLoginSaga(action: ActionType<typeof Actions.userLogin.request>) { function* setLoginSaga(action: ActionType<typeof Actions.setLogin.request>) {
const param = action.payload; const param = action.payload;
try { try {
const { data, errorCode } = yield call(authAPI.usersLogin, param); const { data, errorCode } = yield call(authAPI.setLogin, param);
if (errorCode == '-101') { if (errorCode == '-101') {
throw '계정 정보를 찾을 수 없습니다. 다시 확인해 주세요.'; throw '계정 정보를 찾을 수 없습니다. 다시 확인해 주세요.';
@ -40,12 +40,12 @@ function* userLoginSaga(action: ActionType<typeof Actions.userLogin.request>) {
// } // }
yield put( yield put(
Actions.userLogin.success({ Actions.setLogin.success({
...user.data ...user.data
}) })
); );
} catch (error: any) { } catch (error: any) {
yield put(Actions.userLogin.failure(error)); yield put(Actions.setLogin.failure(error));
// message.error(error); // message.error(error);
} }
@ -106,25 +106,25 @@ function* checkSaga() {
} }
} }
function* userLogoutSaga() { function* setLogoutSaga() {
const accessToken = cookieStorage.getCookie(COOKIE_ACCESS_TOKEN); const accessToken = cookieStorage.getCookie(COOKIE_ACCESS_TOKEN);
try { try {
if (accessToken) { if (accessToken) {
const decodedToken = decode<LoginData>(accessToken); const decodedToken = decode<LoginData>(accessToken);
const res = yield call(authAPI.usersLogout, decodedToken.cstmrSno); const res = yield call(authAPI.setLogout, decodedToken.cstmrSno);
if (res.data == 'SUCCESS') { if (res.data == 'SUCCESS') {
location.href = '/account/login'; location.href = '/account/login';
} }
} }
// yield put(Actions.userLogout.success()); // yield put(Actions.setLogout.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: any) { } catch (error: any) {
yield put(Actions.userLogout.failure(error)); yield put(Actions.setLogout.failure(error));
} }
} }
@ -166,9 +166,9 @@ function* deleteUserSaga(
// yield put(Actions.deleteUser.success(data));; // yield put(Actions.deleteUser.success(data));;
} }
// yield put(Actions.userLogout.success()); // yield put(Actions.setLogout.success());
} catch (error: any) { } catch (error: any) {
yield put(Actions.userLogout.failure(error)); yield put(Actions.setLogout.failure(error));
} }
} }
@ -291,8 +291,8 @@ function* updateUserPwSaga(
} }
export function* authSaga() { export function* authSaga() {
yield takeEvery(Actions.userLogin.request, userLoginSaga); yield takeEvery(Actions.setLogin.request, setLoginSaga);
yield takeEvery(Actions.userLogout.request, userLogoutSaga); yield takeEvery(Actions.setLogout.request, setLogoutSaga);
yield takeEvery(Actions.check.request, checkSaga); yield takeEvery(Actions.check.request, checkSaga);
yield takeEvery(Actions.getUserPage.request, getUserPageSaga); yield takeEvery(Actions.getUserPage.request, getUserPageSaga);
yield takeEvery(Actions.updateUser.request, updateUserSaga); yield takeEvery(Actions.updateUser.request, updateUserSaga);

2
src/modules/utils/customAxiosUtil.ts

@ -51,7 +51,7 @@ clientInstance.interceptors.response.use(
// refreshToken: getRefreshToken() // refreshToken: getRefreshToken()
// }) // })
// ); // );
//store.dispatch(Actions.userLogout.request()); //store.dispatch(Actions.setLogout.request());
// } else { // } else {
// } // }

2
src/views/control/main/ControlMain.js

@ -131,7 +131,7 @@ const ControlMain = () => {
// 로그아웃 // 로그아웃
const handlerLogout = () => { const handlerLogout = () => {
dispatch(Actions.userLogout.request()); dispatch(Actions.setLogout.request());
}; };
// 드론 상세정보 창 닫기 // 드론 상세정보 창 닫기

Loading…
Cancel
Save