File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,34 +7,17 @@ import PersonIcon from '@material-ui/icons/Person';
77import Tooltip from "@material-ui/core/Tooltip" ;
88import 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
2311function 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 >
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ import {
4242 displayValid ,
4343 queryValid ,
4444 updateHash ,
45- baseUrl
45+ baseUrl ,
46+ corsProxy
4647} from "./globals" ;
4748import { isUUID , showNotification } from "./utils" ;
4849import ContextMain from "./ContextMain" ;
@@ -51,6 +52,17 @@ import { withSnackbar } from "notistack";
5152import WarningBox from "./WarningBox" ;
5253import 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 >
You can’t perform that action at this time.
0 commit comments