variable-lime
variable-lime2mo ago

Issue with Keycloak Authentication and Custom Login in React Refine

I'm experiencing an issue with Keycloak authentication in my React Refine application. I use a custom login flow that interacts with an API endpoint to authenticate users and retrieve tokens. However, after login, keycloak.authenticated remains false, and the user is not recognized as authenticated. Additionally, on refreshing the page, the user is redirected to the login screen again. When I don't use custom login, so I do from keycloak login flow, useKeycloak hook is populated as exacted. Thank you in advance!
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @ilir. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it seems like there might be an issue with the way your custom authentication provider is set up. Refine provides a way to use Keycloak for authentication, as shown in the Keycloak example (https://refine.dev/docs/examples/auth-provider/keycloak). Here's how you can create a Refine app with Keycloak authentication:
npm create refine-app@latest -- --example auth-keycloak
npm create refine-app@latest -- --example auth-keycloak
If you're experiencing issues with infinite re-renders, it might be related to the useIsAuthenticated hook. This issue was discussed in a Discord support thread (https://discord.com/channels/837692625737613362/1189348609368531035), where a community member experienced a similar problem. If you're still having trouble, you might want to check out the following resources for more information on how to set up authentication with Refine: - Understanding AuthProvider (https://refine.dev/docs/tutorial/understanding-authprovider/create-authprovider/#setting-authorization-credentials) - DataProvider Error Format (https://refine.dev/docs/api-reference/core/providers/data-provider/#error-format) - Simple REST Usage (https://refine.dev/docs/packages/documentation/data-providers/simple-rest/#usage) Remember, the community is always open to contributions and improvements. If you find a solution to your problem, consider sharing it to help others who might encounter the same issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@699598672131784704> kapa.ai is still learning and improving, please let us know how it did by reacting below
variable-lime
variable-lime2mo ago
can i use keyclak.login without redirection? @kapa.ai @kapa.ai I have used REST API endpoint to retrieve the users token, but as i can see its I am not logging in the user, keycloak instance is empty, and I cant use any of useKaycloak() hook information. please advice