'keycloak init method gives authenticated false even when i login a with valid user

Hello I am using keycloak with react , i used some keycloak code that i got from internet for keycloak and react integration . the problem is that when i use that code initially when i login in and get redirect from the keycloak login theme the authenticated is true which is okay . but as i refresh the page it is no longer true and become false.

here is the code:

         keycloak
              .init({ checkLoginIframe: false })
              .then((authenticated) => {
                console.log("authentication status",authenticated)
    
          }).catch((err)=>{
           
    console.log("error",err)

})

I want to make a http request on basis of token but for that i want to check if authentiacted is true or not.

the authenticated is true only first time when i am redirected from keycloak login page but as i refresh page its always false.i am using react for client side.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source