how are we retrieving data from strapi?
Once a user is authenticated and they are now in the backend lets say they go to access posts, it authenticates they can access posts within the refine code but when does it send to strapi to pull the posts? the users token or the jwt token?
5 Replies
Hi @erekyu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In the refine framework, once a user is authenticated, the user's JWT token is stored in the local storage. This token is then used to authenticate subsequent requests to the backend, such as Strapi, to fetch resources like posts.
In the
authProvider
code snippets provided in the extracts, you can see that after a successful login, the JWT token is stored in local storage and also set in the headers of the axios instance:
This axios instance is then used to make requests to the Strapi backend. The Authorization
header with the Bearer
token is included in each request, allowing Strapi to authenticate the request.
So, to answer your question, it's the JWT token of the user that is sent to Strapi to pull the posts after the user is authenticated.
Sources:
- Refine React Invoice Generator 2 (https://refine.dev/blog/refine-react-invoice-generator-2)
- React Admin Panel Tutorial with Chakra UI and Strapi (https://refine.dev/blog/react-admin-tutorial)
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@66380739771379712> kapa.ai is still learning and improving, please let us how it did by reacting below
eager-peach•15mo ago
@kapa.ai then what is the api token used for in the constants file?
Let me check the knowledge base for you. One moment! :books:
----------------------
The API token in the constants file is used for authenticating the application with the backend service. It's a way for the backend service to verify that the requests it's receiving are from a trusted source.
In the context of the refine framework, the API token is used in two scenarios:
1. In the case of the Strapi backend, the API token is used to access the API endpoints from the refine Pdf Invoice Generator app. After creating the token in the Strapi backend, it is placed inside the
src/constants.ts
file. This token is then used by dataProvider
and authProvider
to work with the Strapi API.
Source: Refine React Invoice Generator 3 (https://refine.dev/blog/refine-react-invoice-generator-3)
2. In the case of the Airtable backend, the API token (along with the BASE_ID) is used to connect to the Airtable base. These credentials can be found on the Airtable account page and the base documentation page.
Source: Building a Complete React CRUD App with Airtable (https://refine.dev/blog/react-crud-app-airtable)
So, the API token in the constants file is used to authenticate the application with the backend service, whether it's Strapi or Airtable.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@66380739771379712> kapa.ai is still learning and improving, please let us how it did by reacting below