Keycloak SSO Login in Angular

I am trying to check the keycloak is logged in or not when a user take my website. But the execution end unexpectedly.

In order to check that user is already logged in or not, I am using the following code in my angular project,

var keycloak = new Keycloak({
  url: environment.kc_url,
  realm: environment.kc_realm,
  clientId: environment.kc_client_id,
});
await keycloak
  .init({
    onLoad: 'check-sso',
    redirectUri: "http://localhost:4200/home?loginType=provider"
  });

const tokenDetails = {
  access_token: keycloak.token,
  refresh_token: keycloak.refreshToken,
  refresh_token_exp: keycloak?.refreshTokenParsed?.exp,
};
console.log('Keycloak initialized successfully:', tokenDetails);

Code execution reach till init statement and the execution stop after that. When I check the network calls, I can see the API call for the init and it return 204 as expected. All the information in the init call is correct as well.

And my keycloak configuration is as following,

Tried adding then catch statements. But still code ends without entering in the code block of then or catch. Tried testing with a sample react project as well. It also give me the same error.

If I am using login-required instead of check-sso it is working.

Can anyone have any idea what am I doing wrong here? Felt like a simple solution, but still not able debug.

Could be related to 3rd parties cookie with Keycloak - #2 by deanmaster.

1 Like

I just tried with a local setup. http://telemed.local/app1/web as my web URL and https://localhost:8181/auth as my keycloak. And it is working as expected. I am so confused now.