How to Integrate Refine basic login with token based JWT auth?
Hi, I want to integrate refine login with my backend login service built with JWT auth via API.
3 Replies
Hi @regnregn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To integrate refine login with your JWT-based backend login service, you can create a custom auth provider. Here's an example of how to create an auth provider for JWT authentication:
1. First, create an
authProvider
object with the necessary methods like login
, logout
, check
, and optionally getPermissions
and getIdentity
. In the login
method, you'll need to make an API call to your backend login service and handle the JWT token.
2. Next, import the authProvider
object into your main App
component and pass it to the <Refine>
component.
3. If you want to create a custom login page, you can use the useLogin
hook from refine. Here's an example of how to use it:
For more information, you can refer to the useLogin documentation (https://refine.dev/docs/api-reference/core/hooks/auth/useLogin).
Remember to replace the placeholders like your_token_key
and your_login_api_url
with your actual values.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@336843331416096768> kapa.ai is still learning and improving, please let us how it did by reacting below
robust-apricot•2y ago
This can be done in many ways and refine does not have a opinion on this. It can be done as you wish. The suggestions provided by the bot are good. Additionally, you can follow the
authProvider
tutorial to learn how refine simplifies the authentication process.
https://refine.dev/docs/tutorial/understanding-authprovider/index/