diff --git a/src/App.js b/src/App.js index f042388..824b464 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,21 @@ const App = () => { const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw'); const [loggedBarHover, setLoggedBarHover] = React.useState(false); + React.useEffect(() => { + if (sessionStorage.getItem('logged') !== 'yes') { + if (KeyCloakService.isLoggedIn()) + sessionStorage.setItem('logged', 'yes'); + } + + setTimeout(() => { + if (sessionStorage.getItem('logged') === 'yes') { + if (!KeyCloakService.isLoggedIn()) { + KeyCloakService.doLogin(); + } + } + }, 200); + }); + const loggedBarVisibleHandler = () => { if (loggedBarVisible === '0' && !loggedBarHover) setLoggedBarVisible('100vw'); diff --git a/src/services/KeyCloakService.js b/src/services/KeyCloakService.js index b289657..1dd0a13 100644 --- a/src/services/KeyCloakService.js +++ b/src/services/KeyCloakService.js @@ -1,17 +1,17 @@ import Keycloak from 'keycloak-js'; -const _kc = new Keycloak({ - url: 'https://auth-dev.csi.wmi.amu.edu.pl/', - realm: 'gonito-dev', - clientId: 'gonito-dev-localhost' -}); - // const _kc = new Keycloak({ // url: 'https://auth-dev.csi.wmi.amu.edu.pl/', // realm: 'gonito-dev', -// clientId: 'gonito-dev-heroku' +// clientId: 'gonito-dev-localhost' // }); +const _kc = new Keycloak({ + url: 'https://auth-dev.csi.wmi.amu.edu.pl/', + realm: 'gonito-dev', + clientId: 'gonito-dev-heroku' +}); + // const _kc = new Keycloak({ // url: 'http://0.0.0.0:8080', // realm: 'test', @@ -36,7 +36,10 @@ const initKeycloak = (onAuthenticatedCallback) => { const doLogin = _kc.login; -const doLogout = _kc.logout; +const doLogout = () => { + sessionStorage.clear(); + _kc.logout(); +}; const getToken = () => _kc.token;