I added the following code to the click event handler of the login button-
onClick={() => {
alert("User logged in");
const keycloak = Keycloak({
realm: "Showcase",
url: "https://*****/auth/",
clientId: "****",
});
keycloak
.init({ onLoad: "login-required" })
.then((authenticated) => {
if (authenticated) {
alert("Authernicated");
alert(JSON.stringify(keycloak));
// setTimeout(5000)
keycloak.loadUserInfo().then((userInfo) => {
alert(JSON.stringify(userInfo));
});
setTimeout(function () {
alert("time out");
alert(JSON.stringify(keycloak));
alert(authenticated);
//this.setState({ keycloak: keycloak, authenticated: authenticated })
// setTimeout(5000)
keycloak.loadUserInfo().then((userInfo) => {
alert(JSON.stringify(userInfo));
});
}, 500);
} else {
alert("not");
}
});
}}
The logic within then doesn’t get executed on clicking for the first time .
After clicking the second time only I see the alerts.
Can someone help me fix this issue?