- If the problem persists, please contact the HuBMAP Help Desk at help@hubmapconsortium.org -
+ If the problem persists, please contact the HuBMAP Help Desk at help@hubmapconsortium.org +
diff --git a/src/src/App.css b/src/src/App.css index e8497952..c74bdf08 100644 --- a/src/src/App.css +++ b/src/src/App.css @@ -70,6 +70,10 @@ margin-right: 2px; } +.logout button div.MuiLoadingButton-loadingIndicator span{ + color: white; +} + .inline-icon { margin-right: 1em; } diff --git a/src/src/App.js b/src/src/App.js index 9e32a480..53dc4477 100644 --- a/src/src/App.js +++ b/src/src/App.js @@ -31,6 +31,7 @@ import IconButton from '@mui/material/IconButton'; import AnnouncementTwoToneIcon from '@mui/icons-material/AnnouncementTwoTone'; import {ingest_api_all_groups,ingest_api_users_groups} from './service/ingest_api'; +import {api_validate_token} from './service/search_api'; import {ubkg_api_get_dataset_type_set,ubkg_api_get_organ_type_set} from "./service/ubkg_api"; import {sortGroupsByDisplay} from "./service/user_service"; import {BuildError} from "./utils/error_helper"; @@ -60,13 +61,15 @@ import Forms from "./components/uuid/forms"; export function App (props){ let navigate = useNavigate(); + var [expiredKey,setExpiredKey ] = useState(false); + var [loginError,setLoginError ] = useState(""); var [loginDialogRender, setLoginDialogRender] = useState(false); var [successDialogRender, setSuccessDialogRender] = useState(false); var [snackMessage, setSnackMessage] = useState(""); var [showSnack, setShowSnack] = useState(false); var [newEntity, setNewEntity] = useState(null); var [authStatus, setAuthStatus] = useState(false); - var [unregStatus, setUnegStatus] = useState(false); + var [unregStatus, setUnregStatus] = useState(false); var [groupsToken, setGroupsToken] = useState(null); var [allGroups, setAllGroups] = useState(null); var [timerStatus, setTimerStatus] = useState(true); @@ -75,8 +78,10 @@ export function App (props){ var [organList, setOrganList] = useState(); var [userGroups, setUserGroups] = useState({}); var [userDataGroups, setUserDataGroups] = useState({}); + var [userDev, setUserDev] = useState(false); - var [regStatus, setRegStatus] = useState(false); + // var [regStatus, setRegStatus] = useState(false); + var [isLoggingOut, setIsLoggingOut] = useState(false); var [isLoading, setIsLoading] = useState(true); var [dtloading, setDTLoading] = useState(true); var [bannerTitle,setBannerTitle] = useState(); @@ -87,11 +92,49 @@ export function App (props){ Datasets:["Registering individual datasets is currently disabled.","/new/upload"], }); + useEffect(() => { + // API Key Validity Check + console.debug('%c◉ API Key Validity ', 'color:#00ff7b',localStorage.getItem("info") ); + if(localStorage.getItem("info") ){ + console.debug('%c◉ localStorage.getItem("info") ', 'color:#00ff7b', localStorage.getItem("info")); + // try { + api_validate_token(JSON.parse(localStorage.getItem("info")).groups_token) + .then((results) => { + console.debug('%c◉ results ', 'color:#00ff7b', results); + if(results.error && results.error.response && results.error.response.status){ + console.debug('%c◉ results.error.response.data ', 'color:#ff005d', results.error.response.data); + console.debug('%c◉ results.error.response.data.error ', 'color:#ff005d', results.error.response.data.error?results.error.response.data.error:"NOMESSAGE"); + setLoginError(results.error.response.data.error ? results.error.response.data.error : "API Key Error"); + console.debug('%c◉ results.error.response.status', 'color:#00ff7b',results.error.response.status ); + if(results.error.response.status === 401){ + console.debug('%c◉ EXPIRED ', 'color:#ff005d' ); + setExpiredKey(true); + // setTimerStatus(false); + // setIsLoading(false); + // setAuthStatus(false); + // // reportError("error", "API Key Expired"); + // localStorage.removeItem('info'); + } + }else if(!results.error){ + console.debug('%c◉ API Key OK ', 'color:#00ff7b', results); + } + }) + .catch((err) => { + console.debug('%c⭗', 'color:#ff005d', "API Key Validity ERR", err ); + }) + + }else{ + console.debug('%c◉ No Local Storage Key to check validity against ', 'color:#00ff7b', ); + } + + + },[]) useEffect(() => { console.debug("useEffect URL/Info"); let url = new URL(window.location.href); let info = url.searchParams.get("info"); + if (info !== null) { localStorage.setItem("info", info); localStorage.setItem("isAuthenticated", true); @@ -99,59 +142,34 @@ export function App (props){ window.location.replace(`${process.env.REACT_APP_URL}`); } - if(localStorage.getItem("info") ){ - console.debug('%c◉ localStorage.getItem("info") ', 'color:#00ff7b', localStorage.getItem("info")); - try { - ingest_api_users_groups(JSON.parse(localStorage.getItem("info")).groups_token).then((results) => { - // console.debug("LocalStorageAuth", results); - - if (results && results.status === 200) { - // console.debug("LocalStorageAuth", results); - setUserGroups(results.results); - setUserDataGroups(results.results); - if (results.results.length > 0) { - setRegStatus(true); - for (let group in results.results) { - if(results.results[group].displayname.includes("IEC")){ - setUserDev(true) - } + try { + ingest_api_users_groups(JSON.parse(localStorage.getItem("info")).groups_token).then((results) => { + console.debug('%c◉ RESULTS ', 'color:#00ff7b', results); + if (results && results.status === 200) { + setUserGroups(results.results); + setUserDataGroups(results.results); + if (results.results.length > 0) { + for (let group in results.results) { + if(results.results[group].displayname.includes("IEC")){ + setUserDev(true) } } - setGroupsToken(JSON.parse(localStorage.getItem("info")).groups_token); - setTimerStatus(false); - setIsLoading(false); - setAuthStatus(true); - } else if (results && results.status === 401) { - console.debug('%c◉ FAIL WITH 410 ', 'color:#00ff7b', ); - setGroupsToken(null); - setAuthStatus(false); - setRegStatus(false); - setTimerStatus(false); - setIsLoading(false); - if (localStorage.getItem("isHubmapUser")) { - // If we were logged out and we have an old token, - // We should promopt to sign back in - CallLoginDialog(); - } - } else if (results && results.status === 403 && results.results === "User is not a member of group HuBMAP-read") { - // console.debug("HERE results", results, results.results); - setAuthStatus(true); - setRegStatus(false); - setUnegStatus(true); - setIsLoading(false); + } + setGroupsToken(JSON.parse(localStorage.getItem("info")).groups_token); + setTimerStatus(false); + setIsLoading(false); + setAuthStatus(true); } }); - }catch(error){ - console.debug('%c◉ FAIL WITH ERROR 410 ', 'color:#ff0000', ); - setTimerStatus(false); - setIsLoading(false) - throw new Error(error); - } - }else{ + }catch(error){ + console.debug('%c◉ error, no results', 'color:#ff0000',error ); setTimerStatus(false); setIsLoading(false) - setAuthStatus(false); + // localStorage.clear(); + // throw new Error(error); + } + }, [ ]); useEffect(() => { @@ -172,16 +190,10 @@ export function App (props){ }) }) .catch(error => { - if (unregStatus) { - setGroupsToken(JSON.parse(localStorage.getItem("info")).groups_token); - setTimerStatus(false); - CallLoginDialog(); - } else { console.debug('%c⭗', 'color:#ff005d', "APP ubkg_api_get_assay_type_set ERROR", error); - reportError(error) - } + reportError(error) }); - }, [unregStatus ]); + }, [ ]); useEffect(() => { if(localStorage.getItem("info")){ @@ -227,27 +239,19 @@ export function App (props){ console.debug('%c◉ stripUrl ', 'color:#00ff7b', stripUrl); } },[]) + - function clearAuths() { - console.debug('%c◉ CLEAR AUTHS ', 'color:#00ff7b' ); - if(process.env.REACT_APP_URL == "http://localhost:8585"){ - console.debug('%c◉ clearAuths start ', 'color:#00ff7b' ); - return new Promise((resolve) => { - setTimeout(() => { // Give it a chance to cleaer the local storage - localStorage.removeItem("info"); - localStorage.removeItem("isAuthenticated"); - resolve(); - }, 2000); - }); - } - } - function Logout(){ - clearAuths().then((response) => { - console.debug('%c◉ response', 'color:#00ff7b',response ); - window.location.replace(`${process.env.REACT_APP_DATAINGEST_API_URL}/logout`) - }) + function Logout(e){ + setIsLoggingOut(true); + localStorage.removeItem('info'); + window.location.replace(`${process.env.REACT_APP_DATAINGEST_API_URL}/logout`) + }; + + function closeExpiredSnack(){ + // setExpiredKey(false) + // window.location.reload(); }; function handleCancel(){ @@ -296,6 +300,7 @@ export function App (props){ const app_info_storage = localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")) : ""; const { search } = useLocation(); + // @TODO: is search itself already handling this / is this an old prop drill? const queryParams = new URLSearchParams(search); const queryEntity = queryParams.has("entity_type")?queryParams.get("entity_type"):null const queryKeyword = queryParams.has("keywords")?queryParams.get("keywords"):null @@ -324,257 +329,237 @@ export function App (props){ } return ( -