Skip to content

Commit 9631e09

Browse files
committed
wip
1 parent 940fa54 commit 9631e09

2 files changed

Lines changed: 21 additions & 22 deletions

File tree

apps/model_catalog/src/AuthWidget.jsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,17 @@ import PersonIcon from '@material-ui/icons/Person';
77
import Tooltip from "@material-ui/core/Tooltip";
88
import ContextMain from "./ContextMain";
99

10-
import { corsProxy } from "./globals";
11-
12-
13-
async function getUserInfo(auth) {
14-
const config = {
15-
headers: {
16-
'Authorization': 'Bearer ' + auth.token,
17-
}
18-
}
19-
return axios.get(corsProxy + "https://idm.ebrains.eu/users/userinfo", config);
20-
}
21-
2210

2311
function AuthWidget(props) {
2412

2513
const context = React.useContext(ContextMain);
2614
const [auth] = context.auth;
2715

28-
if (auth.authenticated || props.currentUser) {
29-
if (!props.currentUser) {
30-
getUserInfo(auth).then((userInfo) => {
31-
console.log(userInfo);
32-
props.setCurrentUser(userInfo.preferred_username);
33-
});
34-
};
16+
React.useEffect(() => {}, [props, auth]);
3517

18+
if (props.currentUser) {
3619
return (
37-
<Tooltip title={props.currentUser || "anonymous"}>
20+
<Tooltip title={props.currentUser}>
3821
<IconButton variant="outlined">
3922
<PersonIcon />
4023
</IconButton>

apps/model_catalog/src/ValidationFramework.jsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import {
4242
displayValid,
4343
queryValid,
4444
updateHash,
45-
baseUrl
45+
baseUrl,
46+
corsProxy
4647
} from "./globals";
4748
import { isUUID, showNotification } from "./utils";
4849
import ContextMain from "./ContextMain";
@@ -51,6 +52,17 @@ import { withSnackbar } from "notistack";
5152
import WarningBox from "./WarningBox";
5253
import AuthWidget from "./AuthWidget";
5354

55+
56+
async function getUserInfo(auth) {
57+
const config = {
58+
headers: {
59+
'Authorization': 'Bearer ' + auth.token,
60+
}
61+
}
62+
return axios.get(corsProxy + "https://idm.ebrains.eu/users/userinfo", config);
63+
}
64+
65+
5466
// if working on the appearance/layout set globals.DevMode=true
5567
// to avoid loading the models and tests over the network every time;
5668
// instead we use the local sample_data_models and sample_data_tests files
@@ -409,6 +421,11 @@ class ValidationFramework extends React.Component {
409421
setStatus(response.data.status)
410422
});
411423

424+
getUserInfo(this.props.auth).then((userInfo) => {
425+
console.log(userInfo);
426+
this.setState({currentUser: userInfo.preferred_username})
427+
});
428+
412429
datastore
413430
.getValidFilterValues()
414431
.then((vocab) => {
@@ -1223,7 +1240,6 @@ class ValidationFramework extends React.Component {
12231240
</Tooltip>
12241241
<AuthWidget
12251242
currentUser={this.state.currentUser}
1226-
setCurrentUser={(user) => this.setState({currentUser: user})}
12271243
/>
12281244
</div>
12291245
</div>

0 commit comments

Comments
 (0)