generated from UNDP-Data/dv-ui-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update staging to resolve the naming issue and fetching the token if …
…expired
- Loading branch information
1 parent
e63c821
commit 6047395
Showing
36 changed files
with
806 additions
and
820 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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable no-param-reassign */ | ||
import axios from 'axios'; | ||
import QueryString from 'qs'; | ||
import { API_BASEURL } from '../Constants'; | ||
import { refreshHandler } from '../Utils/AuthStatusHandler'; | ||
import { getLocalStorage, setLocalStorage } from '../Utils/UpdateLocalStrage'; | ||
|
||
export const axiosInstance = axios.create({ | ||
baseURL: API_BASEURL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
access_token: getLocalStorage().token, | ||
}, | ||
paramsSerializer: { | ||
serialize: params => { | ||
return QueryString.stringify(params, { arrayFormat: 'repeat' }); | ||
}, | ||
}, | ||
timeout: 60000, | ||
}); | ||
|
||
axiosInstance.interceptors.request.use( | ||
async config => { | ||
const { token, tokenExp } = getLocalStorage(); | ||
if (!token || !tokenExp || new Date(tokenExp as string) < new Date()) { | ||
const [newAccessToken, newAccessTokenExp] = await refreshHandler(); | ||
if (newAccessToken && newAccessTokenExp) { | ||
config.headers.access_token = newAccessToken; | ||
setLocalStorage('token', String(newAccessToken)); | ||
setLocalStorage('tokenExp', String(newAccessTokenExp)); | ||
} | ||
} else { | ||
config.headers.access_token = token; | ||
} | ||
|
||
return config; | ||
}, | ||
error => { | ||
return Promise.reject(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './userCalls'; | ||
export * from './choicesCalls'; | ||
export * from './signalsCall'; | ||
export * from './trendsCalls'; |
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.