Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { APP_ENV, getLoginUrl } from '@lib/config';
import { Configuration, GameEventConsumeApi } from '@uniquegood/realworld-statistics-interface';
import axios from 'axios';
import { decodeJwt } from 'jose';
import { memoizedPostRefreshAccessToken } from '@lib/apis/core/postRefreshAccessToken';
import { getLocalStorage, setLocalStorage } from '@lib/utils/localStorage';
import { authApi } from '@lib/apis/auth';
import { memoizedApiAuthReissueGet } from '@lib/apis/auth/apiAuthReissueGet';
import { mobileInterceptRequest } from '@lib/apis';
export const STATISTICS_SERVER_HOST = {
production: 'api.realworld.to',
development: 'api-test.realworld.to'
}[APP_ENV];
const configuration = new Configuration({ basePath: `https://${STATISTICS_SERVER_HOST}` });
const defaultAxiosInstance = axios.create({
baseURL: `https://${STATISTICS_SERVER_HOST}`
});
const tokenRefreshAxiosInstance = axios.create({
baseURL: `https://${STATISTICS_SERVER_HOST}`
});
const mobileTokenRefreshAxiosInstance = axios.create({
baseURL: `https://${STATISTICS_SERVER_HOST}`
});
tokenRefreshAxiosInstance.interceptors.request.use(async (config) => {
let token: string | undefined;
try {
const {
data: { token: newAccessToken, refreshToken: newRefreshToken }
} = await memoizedApiAuthReissueGet();
if (newAccessToken && newRefreshToken) {
setLocalStorage('accessToken', newAccessToken);
setLocalStorage('refreshToken', newRefreshToken);
} else {
throw new Error('No token or refreshToken');
}
token = newAccessToken;
} catch (e) {
alert('리얼월드 로그인이 필요한 콘텐츠입니다. 로그인 페이지로 이동합니다.');
window.location.href = getLoginUrl(window.location.href);
}
config.headers.Authorization = `Bearer ${token}`;
return config;
});
mobileTokenRefreshAxiosInstance.interceptors.request.use(mobileInterceptRequest);
export const gameEventConsumeWithTokenApi = new GameEventConsumeApi(
configuration,
undefined,
tokenRefreshAxiosInstance
);
export const gameEventConsumeForWebviewApi = new GameEventConsumeApi(
configuration,
undefined,
mobileTokenRefreshAxiosInstance
);
|