In this section, we'll properly wire up posting questions and answers to our REST API. All of our changes will be in QuestionsData.ts—our user interface components will be unchanged.
Using fetch to interact with authenticated REST API endpoints
Posting a question to the REST API
We are going to change the implementation for posting a question to use an access token from Auth0:
- Let's start by importing the function that gets the access token from Auth0 into QuestionsData.ts:
import { getAccessToken } from './Auth';
- Let's revise the implementation of the postQuestion function to the following:
export const postQuestion = async (
question: PostQuestionData,
): Promise<QuestionData | undefined...