dont log out after refresh

This commit is contained in:
mattyl006 2022-10-12 18:36:44 +02:00
parent 9ac9e742c3
commit 9ca7b15ae1
2 changed files with 26 additions and 8 deletions

View File

@ -19,6 +19,21 @@ const App = () => {
const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw'); const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw');
const [loggedBarHover, setLoggedBarHover] = React.useState(false); 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 = () => { const loggedBarVisibleHandler = () => {
if (loggedBarVisible === '0' && !loggedBarHover) if (loggedBarVisible === '0' && !loggedBarHover)
setLoggedBarVisible('100vw'); setLoggedBarVisible('100vw');

View File

@ -1,17 +1,17 @@
import Keycloak from 'keycloak-js'; 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({ // const _kc = new Keycloak({
// url: 'https://auth-dev.csi.wmi.amu.edu.pl/', // url: 'https://auth-dev.csi.wmi.amu.edu.pl/',
// realm: 'gonito-dev', // 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({ // const _kc = new Keycloak({
// url: 'http://0.0.0.0:8080', // url: 'http://0.0.0.0:8080',
// realm: 'test', // realm: 'test',
@ -36,7 +36,10 @@ const initKeycloak = (onAuthenticatedCallback) => {
const doLogin = _kc.login; const doLogin = _kc.login;
const doLogout = _kc.logout; const doLogout = () => {
sessionStorage.clear();
_kc.logout();
};
const getToken = () => _kc.token; const getToken = () => _kc.token;