-
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.
Bug/prod portal resource display issue (#261)
* #260: updated site parser to handle site workers in Maint/ PreMaint * #260: added maintenance worker table to site detail page" * #260: replaced mock data with API data * #257: disabled auto-refresh-token function * #255: minor wording fixe * #260: removed console logs * #260: fixed table site link
- Loading branch information
Showing
10 changed files
with
86 additions
and
61 deletions.
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 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
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
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
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
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,58 +1,17 @@ | ||
import { createIdToken, refreshToken, revokeToken } from "../services/credentialManagerService.js"; | ||
import { default as portalData } from "../services/portalData.json"; | ||
import { createIdToken } from "../services/credentialManagerService.js"; | ||
import { toast } from "react-toastify"; | ||
|
||
const autoRevokeTokens = async () => { | ||
try { | ||
await revokeToken(localStorage.getItem("refreshToken")); | ||
} catch (err) { | ||
console.log("Failed to revoke token."); | ||
} | ||
} | ||
|
||
export const autoCreateTokens = async (projectId) => { | ||
// clear previous autoRefreshToken interval if there is any | ||
if (localStorage.getItem("refreshTokenIntervalId")) { | ||
clearInterval(localStorage.getItem("refreshTokenIntervalId")); | ||
} | ||
|
||
try { | ||
// call credential manager to generate tokens. | ||
// parameters: project and scope, "all" for both by default. | ||
const { data: res } = await createIdToken(projectId, "all"); | ||
localStorage.setItem("idToken", res["data"][0].id_token); | ||
localStorage.setItem("refreshToken", res["data"][0].refresh_token); | ||
|
||
// Auto refresh token every 55min | ||
const refreshTokenIntervalId = setInterval(() => { | ||
if(localStorage.getItem("refreshTokenIntervalId")) { | ||
clearInterval(localStorage.getItem("refreshTokenIntervalId")); | ||
} | ||
autoRefreshTokens(projectId); | ||
} | ||
, portalData["autoRefreshTokenInterval"]); | ||
localStorage.setItem("refreshTokenIntervalId", refreshTokenIntervalId); | ||
return res["data"][0]; | ||
} | ||
catch (err) { | ||
toast.error("Unable to obtain authentication token, the likely reason is you are not a member of any projects."); | ||
} | ||
} | ||
|
||
export const autoRefreshTokens = async (projectId) => { | ||
const oldRefreshToken = localStorage.getItem("refreshToken"); | ||
try { | ||
const { data: res } = await refreshToken(projectId, "all", oldRefreshToken); | ||
localStorage.setItem("idToken", res["data"][0].id_token); | ||
localStorage.setItem("refreshToken", res["data"][0].refresh_token); | ||
} catch (err) { | ||
toast.error("Failed to refresh necessary tokens to view slice information. Please try again later."); | ||
// if refresh_token isn't working either | ||
// start over by calling create_token when user reloads the page | ||
// 1. call cm revoke_token with old refresh token | ||
autoRevokeTokens(); | ||
// 2. clear id_token and refresh_token in local storage | ||
localStorage.removeItem("idToken"); | ||
localStorage.removeItem("refreshToken"); | ||
} | ||
} |