Error 401 when performing post request for an API itself

Asked

Viewed 32 times

0

Hello, I am trying to make a post request for an API of my own in order to simulate a "like", the problem is that it is always returned the error 401 whenever I post request, however if I perform a delete request it is performed. I wonder if the problem would be in the way I am performing the post or if the problem might involve some kind of bug regarding authentication in the API(Because even if it is authenticated, the post is not yet realized.)

Below is the code referring to the Like component and right after the Excuse.

Enjoy:

import React from 'react';
import api from '../api';
import { getJwt } from './auth/jwt';


 export default class Curtir extends React.Component {

    addCurtida = (slug) =>{
        slug = this.props.slug
        const jwt = getJwt();
        const response = api.post(`/artigos/`+slug+`/curtir`,{headers: { Authorization: `Token ${jwt}` }})
        console.log(response)
    }
    render(){
        return(
            <button onClick={this.addCurtida} alt="Curtir" type="submit"><i class="fas fa-thumbs-up"></i></button>
        )
    }

}

Neglect:

import React from 'react';
import api from '../api';
import { getJwt } from './auth/jwt';

export default class Descurtir extends React.Component {

    DesfazerCurtida = (slug) =>{
        slug = this.props.slug
        const jwt = getJwt();
        const response = api.delete(`/artigos/`+slug+`/curtir`,{headers: { Authorization: `Token ${jwt}` }})
        console.log(response)
    }
    render(){
        return(
            <button onClick={this.DesfazerCurtida} alt="Descurtir" type="submit"><i class="fas fa-thumbs-down"></i></button>
        )
    }

}

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.