real keycloak instance

This commit is contained in:
mattyl006 2022-10-05 17:28:07 +02:00
parent 49ec6d3897
commit e82e62da23
3 changed files with 11 additions and 22 deletions

View File

@ -18,6 +18,11 @@ import LoggedBar from './components/elements/LoggedBar';
const App = () => { const App = () => {
const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw'); const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw');
React.useEffect(() => {
console.log('czy zalogowany');
console.log(KeyCloakService.isLoggedIn());
});
const loggedBarVisibleHandler = () => { const loggedBarVisibleHandler = () => {
if (loggedBarVisible === '0') if (loggedBarVisible === '0')
setLoggedBarVisible('100vw'); setLoggedBarVisible('100vw');

View File

@ -1,18 +0,0 @@
const loginTest = () => {
let data = {
client_id: 'Id_of_your_client',
username: 'test',
password: 'test',
grant_type: 'password'
};
fetch('http://0.0.0.0:8080/auth/realms/test/protocol/openid-connect/token', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(res => {
console.log('Request complete! response:', res);
});
};
export default loginTest;

View File

@ -1,9 +1,9 @@
import Keycloak from 'keycloak-js'; import Keycloak from 'keycloak-js';
const _kc = new Keycloak({ const _kc = new Keycloak({
url: 'http://0.0.0.0:8080/', url: 'https://auth-dev.csi.wmi.amu.edu.pl/',
realm: 'test', realm: 'gonito-dev',
clientId: 'test' clientId: 'gonito-dev-heroku'
}); });
const initKeycloak = (onAuthenticatedCallback) => { const initKeycloak = (onAuthenticatedCallback) => {
@ -13,8 +13,10 @@ const initKeycloak = (onAuthenticatedCallback) => {
pkceMethod: 'S256', pkceMethod: 'S256',
}) })
.then((authenticated) => { .then((authenticated) => {
console.log('user is authenticated!');
console.log(isLoggedIn());
if (!authenticated) { if (!authenticated) {
console.log('user is not authenticated..!'); console.log('user is NOT authenticated..!');
} }
onAuthenticatedCallback(); onAuthenticatedCallback();
}) })