extended-salmon
extended-salmon16mo ago

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
kapa.ai
kapa.ai16mo ago
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:
localStorage.setItem(TOKEN_KEY, data.jwt);
axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${data.jwt}`;
localStorage.setItem(TOKEN_KEY, data.jwt);
axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${data.jwt}`;
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: ----------------------
kapa.ai
kapa.ai16mo ago
<@66380739771379712> kapa.ai is still learning and improving, please let us how it did by reacting below
extended-salmon
extended-salmon16mo ago
@kapa.ai then what is the api token used for in the constants file?
kapa.ai
kapa.ai16mo ago
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.
export const API_URL = "<http://localhost:1337";>
export const TOKEN_KEY = "625b118353b2924b459527cd39f7ca792a870cc13619562a3e3f8ee6908519c581bcabb8152cbd10913e72d9adf725e6bd99b8793632b34d1dd952544e3bd883eaba7c3ab169308cd29730267247147d20af102d70a311d515d9b5ab06384e0a2418fe47ecda895d74d87bbcf6bbc74d9b318d5795fcf7be1691ed4524d73621";
export const API_URL = "<http://localhost:1337";>
export const TOKEN_KEY = "625b118353b2924b459527cd39f7ca792a870cc13619562a3e3f8ee6908519c581bcabb8152cbd10913e72d9adf725e6bd99b8793632b34d1dd952544e3bd883eaba7c3ab169308cd29730267247147d20af102d70a311d515d9b5ab06384e0a2418fe47ecda895d74d87bbcf6bbc74d9b318d5795fcf7be1691ed4524d73621";
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.
const API_TOKEN = "your-airtable-api-token";
const BASE_ID = "your-airtable-base-id";
const API_TOKEN = "your-airtable-api-token";
const BASE_ID = "your-airtable-base-id";
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: ----------------------
kapa.ai
kapa.ai16mo ago
<@66380739771379712> kapa.ai is still learning and improving, please let us how it did by reacting below