-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from AnotherUniverseAU/DongHyuk
FEAT: Admin Page To Send Marketing Message
- Loading branch information
Showing
5 changed files
with
425 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
import { getNewToken } from "src/apis/getNewToken"; | ||
import { AuthVerify } from "./authVerify"; | ||
import type { InternalAxiosRequestConfig } from "axios"; | ||
import axios from "axios"; | ||
import sendAccessTokenToApp from "./sendAccessTokenToApp"; | ||
import { getNewToken } from 'src/apis/getNewToken'; | ||
import { AuthVerify } from './authVerify'; | ||
import type { InternalAxiosRequestConfig } from 'axios'; | ||
import axios from 'axios'; | ||
import sendAccessTokenToApp from './sendAccessTokenToApp'; | ||
|
||
const BASE_URL = process.env.REACT_APP_BASE_URL; | ||
// const refresh = localStorage.getItem("refreshToken"); | ||
|
||
export const apiRequestGet = async (path: string) => { | ||
const accessToken = (await localStorage.getItem("accessToken")) as string; | ||
const customHttp = axios.create({ | ||
baseURL: `${BASE_URL}`, | ||
timeout: 8000, | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
const accessToken = (await localStorage.getItem('accessToken')) as string; | ||
const customHttp = axios.create({ | ||
baseURL: `${BASE_URL}`, | ||
timeout: 8000, | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
const onFulfilled = async (config: InternalAxiosRequestConfig) => { | ||
const token_validate = await AuthVerify(); | ||
if ( | ||
token_validate === "Access Token Expired" || | ||
token_validate === "None Access Token" | ||
) { | ||
const newAccessToken = await getNewToken(); | ||
await sendAccessTokenToApp(newAccessToken); | ||
if (config.headers) { | ||
config.headers.Authorization = `Bearer ${newAccessToken}`; | ||
} | ||
} | ||
return config; | ||
}; | ||
const onFulfilled = async (config: InternalAxiosRequestConfig) => { | ||
const token_validate = await AuthVerify(); | ||
if (token_validate === 'Access Token Expired' || token_validate === 'None Access Token') { | ||
const newAccessToken = await getNewToken(); | ||
await sendAccessTokenToApp(newAccessToken); | ||
if (config.headers) { | ||
config.headers.Authorization = `Bearer ${newAccessToken}`; | ||
} | ||
} | ||
return config; | ||
}; | ||
|
||
customHttp.interceptors.request.use(onFulfilled, (err) => | ||
Promise.reject(err) | ||
); | ||
customHttp.interceptors.request.use(onFulfilled, (err) => Promise.reject(err)); | ||
|
||
try { | ||
const response = await customHttp.get(path); | ||
if (response.status >= 200 && response.status < 300) { | ||
console.log(`[GET] Data received from ${path}:`, response.data); | ||
return response.data; | ||
} else { | ||
console.error(`[GET] Failed to get data from ${path}:`, response.data); | ||
try { | ||
const response = await customHttp.get(path); | ||
if (response.status >= 200 && response.status < 300) { | ||
console.log(`[GET] Data received from ${path}:`, response.data); | ||
return response.data; | ||
} else { | ||
console.error(`[GET] Failed to get data from ${path}:`, response.data); | ||
} | ||
} catch (error) { | ||
console.error(`[GET] Error fetching data from ${path}:`, error); | ||
} | ||
} catch (error) { | ||
console.error(`[GET] Error fetching data from ${path}:`, error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.