update
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import * as Sentry from '@sentry/react';
|
||||
import axios, { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
||||
import { WHITE_LIST_URLS } from '@/shared/api/urls';
|
||||
import { StorageKeys } from '@/shared/constants/local-storage';
|
||||
import { checkIsAxiosError, getLocalStorage, setLocalStorage } from '@/shared/lib';
|
||||
import {
|
||||
checkIsAxiosError,
|
||||
getLocalStorage,
|
||||
setLocalStorage
|
||||
} from '@/shared/lib';
|
||||
import { finalizeConfig } from './utils';
|
||||
import { appBridge } from '@/utils/appBridge';
|
||||
import { LoginResponse } from '@/entities/user/model/types';
|
||||
import { getHeaderUserAgent } from '@/shared/constants/url';
|
||||
import { useAppBridge } from '@/hooks';
|
||||
import { useUserInfo } from '@/entities/user/lib/use-user-info';
|
||||
import { LoginResponse } from '@/entities/user/model/types';
|
||||
import { useStore } from '@/shared/model/store';
|
||||
import { getHeaderUserAgent } from '@/shared/constants/url';
|
||||
import { login } from '@/entities/user/api/use-login-mutation';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
const onRequestFulfilled = (config: InternalAxiosRequestConfig) => {
|
||||
config.headers['Content-Type'] = 'application/json;charset=UTF-8';
|
||||
@@ -27,7 +32,6 @@ const onRequestFulfilled = (config: InternalAxiosRequestConfig) => {
|
||||
const accessToken = getLocalStorage(StorageKeys.AccessToken);
|
||||
const tokenType = getLocalStorage(StorageKeys.TokenType);
|
||||
config.headers.Authorization = `${tokenType} ${accessToken}`;
|
||||
// config.headers['X-Request-id'] = getLocalStorage(StorageKeys.requestId) ?? '';
|
||||
}
|
||||
return finalizeConfig(config);
|
||||
};
|
||||
@@ -43,32 +47,74 @@ const onResponseFulfilled = (response: AxiosResponse) => {
|
||||
};
|
||||
};
|
||||
|
||||
const onResponseRejected = (error: AxiosError) => {
|
||||
export const onResponseRejected = (error: AxiosError) => {
|
||||
|
||||
console.log('onResponseRejected --> ', error);
|
||||
console.log('error?.status -> ', error?.status, error?.status === 401)
|
||||
|
||||
console.log('onResponseRejected --> ', error)
|
||||
if(error?.status === 401){
|
||||
appBridge.safeCall(() => appBridge.requestRefreshToken()).then((token: LoginResponse) => {
|
||||
setLocalStorage(StorageKeys.TokenType, token.tokenType);
|
||||
setLocalStorage(StorageKeys.AccessToken, token.accessToken);
|
||||
setLocalStorage(StorageKeys.RefreshToken, token.refreshToken);
|
||||
setLocalStorage(StorageKeys.AccessTokenExpiresIn, token.accessTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.RefreshTokenExpiresIn, token.refreshTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.MenuGrants, token.menuGrants);
|
||||
setLocalStorage(StorageKeys.ClientAddressIP, token.clientAddressIP);
|
||||
setLocalStorage(StorageKeys.Requires2FA, token.requires2FA);
|
||||
setLocalStorage(StorageKeys.Usrid, token.usrid);
|
||||
|
||||
useStore.getState().UserStore.setUserInfo({
|
||||
...token
|
||||
if(appBridge.isNativeEnvironment()){
|
||||
appBridge.safeCall(() => appBridge.requestRefreshToken()).then((token: LoginResponse) => {
|
||||
setLocalStorage(StorageKeys.TokenType, token.tokenType);
|
||||
setLocalStorage(StorageKeys.AccessToken, token.accessToken);
|
||||
setLocalStorage(StorageKeys.RefreshToken, token.refreshToken);
|
||||
setLocalStorage(StorageKeys.AccessTokenExpiresIn, token.accessTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.RefreshTokenExpiresIn, token.refreshTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.MenuGrants, token.menuGrants);
|
||||
setLocalStorage(StorageKeys.ClientAddressIP, token.clientAddressIP);
|
||||
setLocalStorage(StorageKeys.Requires2FA, token.requires2FA);
|
||||
setLocalStorage(StorageKeys.Usrid, token.usrid);
|
||||
|
||||
if(appBridge.isNativeEnvironment()){
|
||||
setLocalStorage(StorageKeys.DeviceId, token.deviceId);
|
||||
setLocalStorage(StorageKeys.AppVersion, token.appVersion);
|
||||
}
|
||||
|
||||
useStore.getState().UserStore.setUserInfo({
|
||||
...token
|
||||
});
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
else{
|
||||
let params = {
|
||||
id: 'woowahan5',
|
||||
password: 'nictest00'
|
||||
};
|
||||
login(params).then((result: LoginResponse) => {
|
||||
result.usrid = params.id;
|
||||
|
||||
setLocalStorage(StorageKeys.TokenType, result.tokenType);
|
||||
setLocalStorage(StorageKeys.AccessToken, result.accessToken);
|
||||
setLocalStorage(StorageKeys.RefreshToken, result.refreshToken);
|
||||
setLocalStorage(StorageKeys.AccessTokenExpiresIn, result.accessTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.RefreshTokenExpiresIn, result.refreshTokenExpiresIn);
|
||||
setLocalStorage(StorageKeys.MenuGrants, result.menuGrants);
|
||||
setLocalStorage(StorageKeys.ClientAddressIP, result.clientAddressIP);
|
||||
setLocalStorage(StorageKeys.Requires2FA, result.requires2FA);
|
||||
setLocalStorage(StorageKeys.Usrid, result.usrid);
|
||||
|
||||
if(appBridge.isNativeEnvironment()){
|
||||
setLocalStorage(StorageKeys.DeviceId, result.deviceId);
|
||||
setLocalStorage(StorageKeys.AppVersion, result.appVersion);
|
||||
}
|
||||
|
||||
useStore.getState().UserStore.setUserInfo({
|
||||
...result
|
||||
});
|
||||
location.reload();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return new Promise((_resolve, reject) => {
|
||||
if(checkIsAxiosError(error)){
|
||||
// iOS의 경우 window에서 unload event가 일어날때 네트워크 에러가 발생하곤 해서 이런 케이스를 방지하기 위해 지연시킴
|
||||
// location.href, location.reload 등으로 unload event가 일어나면 자바스크립트 런타임이 초기화되므로 settimeout으로 인한 네트워크 에러가 트리거 x
|
||||
setTimeout(() => reject(error), 300);
|
||||
setTimeout(() => {
|
||||
reject(error);
|
||||
}, 300);
|
||||
}
|
||||
else{
|
||||
reject(error);
|
||||
|
||||
@@ -8,8 +8,6 @@ import {
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import { HeaderNavigation } from '@/widgets/navigation/header';
|
||||
import { FooterNavigation } from '@/widgets/navigation/footer';
|
||||
import { PullToRefresh } from '@/widgets/pull-to-refresh/pull-to-refresh';
|
||||
import { useNavigate } from '@/shared/lib/hooks';
|
||||
import {
|
||||
CodeListItem,
|
||||
CodesSelectParams,
|
||||
@@ -237,12 +235,11 @@ export const SubLayout = () => {
|
||||
id: 'nictest00',
|
||||
password: 'nictest00'
|
||||
};
|
||||
|
||||
*/
|
||||
userParmas = {
|
||||
id: 'woowahan5',
|
||||
password: 'nictest00'
|
||||
};
|
||||
id: 'woowahan5',
|
||||
password: 'nictest00'
|
||||
};
|
||||
|
||||
}
|
||||
callLogin(userParmas).then(() => {
|
||||
@@ -339,7 +336,7 @@ export const SubLayout = () => {
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if(!!mid){
|
||||
//callBusinessProperty();
|
||||
callBusinessProperty();
|
||||
callFindAuthMethod();
|
||||
}
|
||||
}, [mid]);
|
||||
|
||||
Reference in New Issue
Block a user