Error 401 Unauthorized in Axios in React JS

Viewed 26

I was trying to post a comment through Axios. But I am getting the 401 error, even though I have passed the header with the Authorization token. I don't know what is causing this error. Please Help . My boss is yelling at me :) (I am a junior developer).

const handleSubmit = async (e: any) => {
        e.preventDefault();
        const finalComment = { comment };

        try {
            const response = await axios.post(
                `${TEST_API_URL}/user/proposal/comments/admin/create`,
                finalComment,
                {
                    withCredentials: true,
                    headers: {
                        Authorization: `${localStorage.getItem('access_token')}`,
                    },
                }
            )
            console.log(response);
        } catch (error) {
            console.log(error);
        }
}
0 Answers
Related