-
Hi all, I am trying to use a 'useEffect' to invoke the login process instead of a button click as in the example. It works fine if the user is not previously authenticated. But when the user is logged in, and hits logout the token goes to empty string as expected, but when the login function is invoked, the user is not redirected to the keycloak login page and the token is returned. React.useEffect(() => {
if (token == null || token.length === 0) {
console.log("Attempting to login")
console.log("Login => ", login())
}
}, [login, token]) In the image below you see what happens after logout is invoked. Is this an issue with keycloak not logging out fast enough? Is there some suggestion on what I could do to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
On a more general level, what are you trying to achieve? If the token changes, and is set to If you post your use case, it might be easier for us to understand what you're trying to do, and we can aid in finding a solution. I don't see any immediate issues in the snippet you posted, but there might be other issues. |
Beta Was this translation helpful? Give feedback.
-
This will also trigger a new login whenever the token is refreshed, which happens in the background continuously. You probably don't want to redirect your users every 1-10min. Have you looked into the "autoLogin" config parameter? Any reason you can't use this? If you need some more help, posting the "authConfig" and some more context would be useful 🙂 |
Beta Was this translation helpful? Give feedback.
This will also trigger a new login whenever the token is refreshed, which happens in the background continuously. You probably don't want to redirect your users every 1-10min.
Have you looked into the "autoLogin" config parameter? Any reason you can't use this?
If you need some more help, posting the "authConfig" and some more context would be useful 🙂