Fix adding auth header mechanism in constants.js

parent 07a33c68
Pipeline #172665497 passed with stage
in 2 minutes and 58 seconds
import { API_LOGIN_URL } from 'constants/apiConstants';
import { ROUTE_HOMEPAGE } from 'constants/routeConstants';
import history from 'app-history';
import { axios, setToken } from 'services/constants';
import { axios } from 'services/constants';
import { fetchAccessToken, fetchAccessTokenSuccess } from 'state/user/userActions';
export const performLogin = async (username, password, dispatch) => {
......@@ -18,7 +18,6 @@ export const performLogin = async (username, password, dispatch) => {
try{
const accessToken = res.data.data.login.accessToken
setToken(accessToken)
localStorage.setItem("accessToken", accessToken)
await dispatch(fetchAccessTokenSuccess(accessToken, dispatch));
history.push(ROUTE_HOMEPAGE);
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils';
......@@ -28,7 +28,7 @@ const ITEM_DETAIL_QUERY = `
export default class ApiCustomer {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allCustomerImpl{
......@@ -48,7 +48,7 @@ export default class ApiCustomer {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getCustomerImpl (id: ${id}) {
......@@ -63,7 +63,7 @@ export default class ApiCustomer {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveCustomerImpl(${payloadAsParam}) {
......@@ -84,7 +84,7 @@ export default class ApiCustomer {
idCust
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateCustomerImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import cloneDeep from 'lodash/cloneDeep';
import { ENDPOINT } from './constants'
......@@ -12,7 +12,7 @@ description
export default class ApiCurrency {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allCurrencyImpl {
......@@ -29,7 +29,7 @@ export default class ApiCurrency {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveCurrencyImpl (${payloadAsParam}) {
......@@ -45,7 +45,7 @@ export default class ApiCurrency {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getCurrencyImpl (id: ${id}) {
......@@ -62,7 +62,7 @@ export default class ApiCurrency {
const result = { success: false }
try {
await axios.post(ENDPOINT.DELETE, {
await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteCurrencyImpl(idCurr: ${idCurr}) {
......@@ -86,7 +86,7 @@ export default class ApiCurrency {
idCurr: parseInt(idCurr)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateCurrencyImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -17,7 +17,7 @@ width
export default class ApiMasterDataMaterial {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allMaterialImpl {
......@@ -35,7 +35,7 @@ export default class ApiMasterDataMaterial {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveMaterialImpl(${payloadAsParam}) {
......@@ -51,7 +51,7 @@ export default class ApiMasterDataMaterial {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getMaterialImpl (id: ${id}) {
......@@ -65,7 +65,7 @@ export default class ApiMasterDataMaterial {
}
static async delete(idMaterial) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteMaterialImpl(idMaterial: ${idMaterial}) {
......@@ -86,7 +86,7 @@ export default class ApiMasterDataMaterial {
idMaterial: parseInt(idMaterial)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateMaterialImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -11,7 +11,7 @@ description
export default class ApiPaymentMethod {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allPaymentMethodImpl {
......@@ -26,7 +26,7 @@ export default class ApiPaymentMethod {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getPaymentMethodImpl (id: ${id}) {
......@@ -41,7 +41,7 @@ export default class ApiPaymentMethod {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
savePaymentMethodImpl(${payloadAsParam}) {
......@@ -57,7 +57,7 @@ export default class ApiPaymentMethod {
}
static async delete(idPayment) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deletePaymentMethodImpl(idPayment: ${idPayment}) {
......@@ -78,7 +78,7 @@ export default class ApiPaymentMethod {
idPayment: parseInt(idPayment)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updatePaymentMethodImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -12,7 +12,7 @@ processCode
export default class ApiMasterDataProcess {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allProcessImpl {
......@@ -29,7 +29,7 @@ export default class ApiMasterDataProcess {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveProcessImpl(${payloadAsParam}) {
......@@ -45,7 +45,7 @@ export default class ApiMasterDataProcess {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getProcessImpl (id: ${id}) {
......@@ -59,7 +59,7 @@ export default class ApiMasterDataProcess {
}
static async delete(idProcess) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteProcessImpl(idProcess: ${idProcess}) {
......@@ -80,7 +80,7 @@ export default class ApiMasterDataProcess {
idProcess: parseInt(idProcess)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateProcessImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -10,7 +10,7 @@ name
export default class ApiMasterDataRole {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allRoleImpl {
......@@ -25,7 +25,7 @@ export default class ApiMasterDataRole {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveRoleImpl(${payloadAsParam}) {
......@@ -41,7 +41,7 @@ export default class ApiMasterDataRole {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allRoleImpl {
......@@ -56,7 +56,7 @@ export default class ApiMasterDataRole {
}
static async delete(idRole) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteRoleImpl(idRole: ${idRole}) {
......@@ -77,7 +77,7 @@ export default class ApiMasterDataRole {
idRole: parseInt(idRole)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateRoleImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -12,7 +12,7 @@ employeeNumber
export default class ApiUser {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allUserImpl {
......@@ -28,7 +28,7 @@ export default class ApiUser {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveUserImpl(${payloadAsParam}) {
......@@ -44,7 +44,7 @@ export default class ApiUser {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getUserImpl (id: ${id}) {
......@@ -58,7 +58,7 @@ export default class ApiUser {
}
static async delete(idUser) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteUserImpl(idUser: ${idUser}) {
......@@ -79,7 +79,7 @@ export default class ApiUser {
idUser: parseInt(idUser)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateUserImpl (${payloadAsParam}) {
......
import { axios } from './constants';
import { axiosWithAccessToken } from './constants';
import { ENDPOINT } from './constants'
import { dictToStringParam, handleSilentApiError } from './utils'
......@@ -29,7 +29,7 @@ paymentMethod {
export default class ApiMasterDataVendor {
static async get() {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
allVendorImpl {
......@@ -48,7 +48,7 @@ export default class ApiMasterDataVendor {
static async create(payload) {
const payloadAsParam = dictToStringParam(payload)
const response = await axios.post(ENDPOINT.CREATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.CREATE, {
query: `
mutation {
saveVendorImpl(${payloadAsParam}) {
......@@ -64,7 +64,7 @@ export default class ApiMasterDataVendor {
}
static async getItem(id) {
const response = await axios.post(ENDPOINT.QUERY, {
const response = await axiosWithAccessToken.post(ENDPOINT.QUERY, {
query: `
query {
getVendorImpl (id: ${id}) {
......@@ -78,7 +78,7 @@ export default class ApiMasterDataVendor {
}
static async delete(idVendor) {
const response = await axios.post(ENDPOINT.DELETE, {
const response = await axiosWithAccessToken.post(ENDPOINT.DELETE, {
query: `
mutation {
deleteVendorImpl(idVendor: ${idVendor}) {
......@@ -99,7 +99,7 @@ export default class ApiMasterDataVendor {
idVendor: parseInt(idVendor)
})
const response = await axios.post(ENDPOINT.UPDATE, {
const response = await axiosWithAccessToken.post(ENDPOINT.UPDATE, {
query: `
mutation {
updateVendorImpl (${payloadAsParam}) {
......
......@@ -10,6 +10,5 @@ export const ENDPOINT = {
// Create axios instance
export const axios = axiosOri.create()
export const setToken = (accessToken) => {
axios.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`
}
\ No newline at end of file
const accessToken = localStorage.getItem("accessToken")
export const axiosWithAccessToken = axiosOri.create({headers: {'Authorization': `Bearer ${accessToken}`}})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment