This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
fix: issue #16 #39
Closed
Closed
fix: issue #16 #39
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
import axios from "axios"; | ||
import store from "../store"; | ||
import { getFreshToken, isTokenExpired } from "@topcoder-platform/tc-auth-lib"; | ||
import { getAuthUserTokens } from "@topcoder/micro-frontends-navbar-app"; | ||
|
||
export const getToken = () => { | ||
return new Promise(async (resolve, reject) => { | ||
const authUserTokens = await getAuthUserTokens(); | ||
const token = authUserTokens ? authUserTokens.tokenV3 : null; | ||
if (token && !isTokenExpired(token)) { | ||
return resolve(token); | ||
} else { | ||
return getFreshToken() | ||
.then((token) => { | ||
resolve(token); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
reject(err); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
export const axiosInstance = axios.create({ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
// request interceptor to pass auth token | ||
axiosInstance.interceptors.request.use((config) => { | ||
return getToken() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yoution just replace this line with |
||
.then((token) => { | ||
config.headers["Authorization"] = `Bearer ${token}`; | ||
return config; | ||
}) | ||
.catch((err) => { | ||
// TODO handle this error somehow | ||
console.log(err); | ||
return config; | ||
}); | ||
}); |
This file contains hidden or 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,84 +1,52 @@ | ||
/** | ||
* Topcoder TaaS Service | ||
*/ | ||
import axios from "axios"; | ||
import { axiosInstance as axios } from "./requestInterceptor"; | ||
import config from "../../config"; | ||
|
||
/** | ||
* Get my teams. | ||
* | ||
* @param {string} tokenV3 login token | ||
* | ||
* @returns {Promise<object[]>} list of teams | ||
*/ | ||
export const getMyTeams = (tokenV3) => { | ||
if (!tokenV3) { | ||
return Promise.resolve({ | ||
data: null, | ||
}); | ||
} | ||
return axios.get(`${config.API.V5}/taas-teams`, { | ||
headers: { Authorization: `Bearer ${tokenV3}` }, | ||
}); | ||
export const getMyTeams = () => { | ||
debugger; | ||
return axios.get(`${config.API.V5}/taas-teams`); | ||
}; | ||
|
||
/** | ||
* Get team by id. | ||
* | ||
* @param {string} tokenV3 login token | ||
* @param {string|number} teamId team id | ||
* | ||
* @returns {Promise<{}>} team object | ||
*/ | ||
export const getTeamById = (tokenV3, teamId) => { | ||
if (!tokenV3) { | ||
return Promise.resolve({ | ||
data: null, | ||
}); | ||
} | ||
return axios.get(`${config.API.V5}/taas-teams/${teamId}`, { | ||
headers: { Authorization: `Bearer ${tokenV3}` }, | ||
}); | ||
export const getTeamById = (teamId) => { | ||
return axios.get(`${config.API.V5}/taas-teams/${teamId}`); | ||
}; | ||
|
||
/** | ||
* Get team position details. | ||
* | ||
* @param {string} tokenV3 login token | ||
* @param {string|number} teamId team id | ||
* @param {string|number} positionId position id | ||
* | ||
* @returns {Promise<object{}>} job object | ||
*/ | ||
export const getPositionDetails = (tokenV3, teamId, positionId) => { | ||
if (!tokenV3) { | ||
return Promise.resolve({ | ||
data: null, | ||
}); | ||
} | ||
return axios.get(`${config.API.V5}/taas-teams/${teamId}/jobs/${positionId}`, { | ||
headers: { Authorization: `Bearer ${tokenV3}` }, | ||
}); | ||
export const getPositionDetails = (teamId, positionId) => { | ||
return axios.get(`${config.API.V5}/taas-teams/${teamId}/jobs/${positionId}`); | ||
}; | ||
|
||
/** | ||
* Patch Position Candidate | ||
* | ||
* @param {string} tokenV3 login token | ||
* @param {string} candidateId position candidate id | ||
* | ||
* @returns {Promise<object{}>} position candidate | ||
*/ | ||
export const patchPositionCandidate = ( | ||
tokenV3, | ||
candidateId, | ||
partialCandidateData | ||
) => { | ||
export const patchPositionCandidate = (candidateId, partialCandidateData) => { | ||
return axios.patch( | ||
`${config.API.V5}/jobCandidates/${candidateId}`, | ||
partialCandidateData, | ||
{ | ||
headers: { Authorization: `Bearer ${tokenV3}` }, | ||
} | ||
partialCandidateData | ||
); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yoution we should not use
@topcoder-platform/tc-auth-lib
directly. We should alwaysgetAuthUserTokens
from@topcoder/micro-frontends-navbar-app