Skip to content

Commit

Permalink
add bearer token for header
Browse files Browse the repository at this point in the history
  • Loading branch information
faris-isa committed May 6, 2021
1 parent 6455608 commit 8d9223a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/views/products/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CTabs,
} from '@coreui/react';

import axiosConfig from "../../axios";
import axiosConfig from "../../api/axios";

import CardHeader from '../.components/CardHeader';
import TableProducts from './components/table/TableProducts';
Expand All @@ -24,10 +24,14 @@ const Products = () => {
const [ongoingprod, setOngoingprod] = useState([]);
const [depracatedprod, setDepracatedprod] = useState([]);
const [load, setLoad] = useState(true);
const token = JSON.parse(sessionStorage.getItem("token"));
let headers = {
authorization: `Bearer ${token}`,
};

const getProducts = async () => {
try {
const products = await axiosConfig.get('/products');
const products = await axiosConfig.get('/products', headers);
const data = products.data;
//filter ongoing
const ongoing = data.reduce((filter, value) => {
Expand Down Expand Up @@ -78,7 +82,7 @@ const Products = () => {
try {
setLoad(true);
const fd = {"status": "deprecated"};
axiosConfig.patch(`/products/status/${id}`, fd)
axiosConfig.patch(`/products/status/${id}`, fd, headers)
.then(res => {
const data = res.data;
if (data.status === 201){
Expand Down Expand Up @@ -135,7 +139,7 @@ const Products = () => {
try {
setLoad(true);
const fd = {"status": "ongoing"};
axiosConfig.patch(`/products/status/${id}`, fd)
axiosConfig.patch(`/products/status/${id}`, fd, headers)
.then(res => {
const data = res.data;
if (data.status === 201){
Expand Down

0 comments on commit 8d9223a

Please sign in to comment.