Pass JWT token to dataprovider
How can I pass the jwt token to the simple-rest dataprovider when making a request?
2 Replies
Hi @BlackBearFTW. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To pass a JWT token to the
simple-rest
data provider when making a request in refine, you can create a custom axios
instance and configure it to include the JWT token in the Authorization
header for every request. Here is a step-by-step guide on how to achieve this:
1. Create a custom axios
instance:
- First, create an axios
instance and set up an interceptor to add the JWT token to the Authorization
header.
2. Update the dataProvider
to use the custom axios
instance:
- Pass the custom axios
instance to the dataProvider
.
Here is an example of how you can do this:
This setup ensures that the JWT token is included in the Authorization
header for every request made by the simple-rest
data provider.
For more information, you can refer to the discussion on GitHub (https://github.com/refinedev/refine/discussions/5880) where a similar solution is provided.
If you need further details, you can also check the documentation (https://refine.dev/docs/data/packages/simple-rest/#url-design) for the simple-rest
package.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@490961337896402944> kapa.ai is still learning and improving, please let us know how it did by reacting below