From 353983c99fafb0cc7822a8443dc30c88b85bcdda Mon Sep 17 00:00:00 2001 From: mattyl006 Date: Fri, 7 Oct 2022 09:54:31 +0200 Subject: [PATCH] keycloak corrections: set checkLoginIframe to false --- src/App.js | 5 ----- src/index.js | 8 ++++---- src/services/KeyCloakService.js | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/App.js b/src/App.js index 7e450ec..8bccc50 100644 --- a/src/App.js +++ b/src/App.js @@ -18,11 +18,6 @@ import LoggedBar from './components/elements/LoggedBar'; const App = () => { const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw'); - React.useEffect(() => { - console.log('czy zalogowany'); - console.log(KeyCloakService.isLoggedIn()); - }); - const loggedBarVisibleHandler = () => { if (loggedBarVisible === '0') setLoggedBarVisible('100vw'); diff --git a/src/index.js b/src/index.js index 189e572..fad2077 100644 --- a/src/index.js +++ b/src/index.js @@ -3,8 +3,8 @@ import ReactDOM from 'react-dom/client'; import './index.css'; import './normalize.css'; import App from './App'; -// import KeyCloakService from './services/KeyCloakService'; -// import HttpService from './services/HttpService'; +import KeyCloakService from './services/KeyCloakService'; +import HttpService from './services/HttpService'; const root = ReactDOM.createRoot(document.getElementById('root')); @@ -14,7 +14,7 @@ const renderApp = () => root.render( ); -// KeyCloakService.initKeycloak(renderApp); -// HttpService.configure(); +KeyCloakService.initKeycloak(renderApp); +HttpService.configure(); renderApp(); \ No newline at end of file diff --git a/src/services/KeyCloakService.js b/src/services/KeyCloakService.js index 5004872..7af44f7 100644 --- a/src/services/KeyCloakService.js +++ b/src/services/KeyCloakService.js @@ -1,20 +1,31 @@ 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' }); +// const _kc = new Keycloak({ +// url: 'http://0.0.0.0:8080', +// realm: 'test', +// clientId: 'test' +// }); + const initKeycloak = (onAuthenticatedCallback) => { _kc.init({ onLoad: 'check-sso', silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html', pkceMethod: 'S256', + checkLoginIframe: false }) .then((authenticated) => { - console.log('user is authenticated!'); - console.log(isLoggedIn()); if (!authenticated) { console.log('user is NOT authenticated..!'); } @@ -31,9 +42,7 @@ const getToken = () => _kc.token; const doRegister = _kc.register; -const isLoggedIn = () => { - return _kc.authenticated; -}; +const isLoggedIn = () => !!_kc.token; const updateToken = (successCallback) => _kc.updateToken(5)