[AccessToken] Token 발급 시 localStorage 저장 후 재발급 하지않도록 변경
This commit is contained in:
1576
com.twin.app.shoptime/package-lock.json
generated
1576
com.twin.app.shoptime/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,28 @@
|
|||||||
import { URLS } from "../api/apiConfig";
|
import { URLS } from "../api/apiConfig";
|
||||||
import { TAxios } from "../api/TAxios";
|
import { TAxios } from "../api/TAxios";
|
||||||
import { types } from "./actionTypes";
|
import { types } from "./actionTypes";
|
||||||
import { getHomeTerms } from "./homeActions";
|
import { changeLocalSettings } from "./commonActions";
|
||||||
|
|
||||||
// IF-LGSP-000 인증코드 요청
|
// IF-LGSP-000 인증코드 요청
|
||||||
export const getAuthenticationCode = () => (dispatch, getState) => {
|
export const getAuthenticationCode = () => (dispatch, getState) => {
|
||||||
|
const { accessToken } = getState().localSettings;
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const onSuccess = (response) => {
|
const onSuccess = (response) => {
|
||||||
console.log("getAuthenticationCode onSuccess: ", response.data);
|
console.log("getAuthenticationCode onSuccess: ", response.data);
|
||||||
|
|
||||||
dispatch({
|
const accessToken = response.data.data.accessToken;
|
||||||
type: types.GET_AUTHENTICATION_CODE,
|
|
||||||
payload: response.data.data.accessToken,
|
/* TOKEN 발급 관련 변경 시 추후 작업 필요 */
|
||||||
});
|
// dispatch({
|
||||||
|
// type: types.GET_AUTHENTICATION_CODE,
|
||||||
|
// payload: response.data.data.accessToken,
|
||||||
|
// });
|
||||||
|
|
||||||
|
dispatch(changeLocalSettings({ accessToken }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFail = (error) => {
|
const onFail = (error) => {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const TAxios = (
|
|||||||
) => {
|
) => {
|
||||||
const checkAccessToken = () => {
|
const checkAccessToken = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const accessToken = getState().device.accessToken;
|
const accessToken = getState().localSettings.accessToken;
|
||||||
if (
|
if (
|
||||||
accessToken ||
|
accessToken ||
|
||||||
baseUrl === URLS.GET_AUTHENTICATION_CODE ||
|
baseUrl === URLS.GET_AUTHENTICATION_CODE ||
|
||||||
@@ -105,8 +105,8 @@ export const TAxios = (
|
|||||||
|
|
||||||
const executeRequest = (accessToken, getState) => {
|
const executeRequest = (accessToken, getState) => {
|
||||||
const httpHeader = getState().common.httpHeader;
|
const httpHeader = getState().common.httpHeader;
|
||||||
const {mbr_no, deviceId} = getState().common.appStatus;
|
const { mbr_no, deviceId } = getState().common.appStatus;
|
||||||
const AUTHORIZATION = { headers: {...httpHeader} };
|
const AUTHORIZATION = { headers: { ...httpHeader } };
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
AUTHORIZATION.headers["lgsp_auth"] = accessToken;
|
AUTHORIZATION.headers["lgsp_auth"] = accessToken;
|
||||||
@@ -114,9 +114,11 @@ export const TAxios = (
|
|||||||
AUTHORIZATION.headers["dvc_id"] = deviceId;
|
AUTHORIZATION.headers["dvc_id"] = deviceId;
|
||||||
|
|
||||||
if (typeof window === "object") {
|
if (typeof window === "object") {
|
||||||
let url = Array.isArray(baseUrl) ? getUrl(getState, baseUrl[0]) : getUrl(getState, baseUrl);
|
let url = Array.isArray(baseUrl)
|
||||||
|
? getUrl(getState, baseUrl[0])
|
||||||
|
: getUrl(getState, baseUrl);
|
||||||
|
|
||||||
if(!url){
|
if (!url) {
|
||||||
//todo error page
|
//todo error page
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -156,7 +158,7 @@ export const TAxios = (
|
|||||||
.then(() => executeRequest(accessToken, getState))
|
.then(() => executeRequest(accessToken, getState))
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
/* 토큰 갱신 실패 처리 */
|
/* 토큰 갱신 실패 처리 */
|
||||||
console.error('tokenRefresh error', e);
|
console.error("tokenRefresh error", e);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
executeRequest(accessToken, getState);
|
executeRequest(accessToken, getState);
|
||||||
|
|||||||
@@ -1,28 +1,32 @@
|
|||||||
import { types } from "../actions/actionTypes";
|
import { types } from "../actions/actionTypes";
|
||||||
import { readLocalStorage, writeLocalStorage } from "../utils/helperMethods";
|
|
||||||
import * as Config from "../utils/Config";
|
import * as Config from "../utils/Config";
|
||||||
|
import { readLocalStorage, writeLocalStorage } from "../utils/helperMethods";
|
||||||
|
|
||||||
const initialLocalSettings = {
|
const initialLocalSettings = {
|
||||||
serverType: Config.DEFAULT_SERVERTYPE,
|
serverType: Config.DEFAULT_SERVERTYPE,
|
||||||
ricCodeSetting: Config.DEFAULT_RIC_CODE
|
ricCodeSetting: Config.DEFAULT_RIC_CODE,
|
||||||
|
accessToken: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateInitialLocalSettings = () => {
|
const updateInitialLocalSettings = () => {
|
||||||
const data = readLocalStorage('localSettings',initialLocalSettings);
|
const data = readLocalStorage("localSettings", initialLocalSettings);
|
||||||
if( Object.keys(data).length !== Object.keys(initialLocalSettings).length){
|
if (Object.keys(data).length !== Object.keys(initialLocalSettings).length) {
|
||||||
writeLocalStorage('localSettings', initialLocalSettings);
|
writeLocalStorage("localSettings", initialLocalSettings);
|
||||||
return initialLocalSettings;
|
return initialLocalSettings;
|
||||||
}else{
|
} else {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const localSettingsReducer = (state = updateInitialLocalSettings(), action) => {
|
export const localSettingsReducer = (
|
||||||
|
state = updateInitialLocalSettings(),
|
||||||
|
action
|
||||||
|
) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case types.CHANGE_LOCAL_SETTINGS: {
|
case types.CHANGE_LOCAL_SETTINGS: {
|
||||||
const newState = Object.assign({}, state, action.payload);
|
const newState = Object.assign({}, state, action.payload);
|
||||||
writeLocalStorage('localSettings', newState);
|
writeLocalStorage("localSettings", newState);
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
Reference in New Issue
Block a user