Skip to content

Commit

Permalink
Merge pull request #24 from andela/bg-axios-throws-auth-error-165439124
Browse files Browse the repository at this point in the history
#165439124: Bug-fix  Axios Throwing Config Errors
  • Loading branch information
abulojoshua1 committed Apr 23, 2019
2 parents f3735c0 + 0eb3e79 commit 6bbfc7d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/axiosConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ const axiosConfig = axios.create({
'content-type': 'application/json',
},
});


export const axiosConfigAuth = axios.create({
baseURL: REACT_APP_BASE_URL,
headers: {
'content-type': 'application/json',
authorization: `Bearer ${localStorage.token}`,
},
});

export default axiosConfig;
4 changes: 2 additions & 2 deletions src/store/actions/articleActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PERSONAL_ARTICLES_FETCHED, AUTHENTICATION_FAILED } from './actionTypes';
import axiosConfig from '../../axiosConfig';
import { axiosConfigAuth } from '../../axiosConfig';

const fetchPersonalArticles = () => dispatch => axiosConfig.request({
const fetchPersonalArticles = () => dispatch => axiosConfigAuth.request({
method: 'get',
url: '/user/articles/',
})
Expand Down
6 changes: 3 additions & 3 deletions src/store/actions/profileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
PROFILE_UPDATE_FAILED,
AUTHENTICATION_FAILED,
} from './actionTypes';
import axiosConfig from '../../axiosConfig';
import { axiosConfigAuth } from '../../axiosConfig';

export const fetchProfile = () => dispatch => axiosConfig.request({
export const fetchProfile = () => dispatch => axiosConfigAuth.request({
method: 'get',
url: 'user/',
})
Expand All @@ -23,7 +23,7 @@ export const fetchProfile = () => dispatch => axiosConfig.request({
payload: error.response.data,
});
});
export const updateProfile = updatedProfileInfo => dispatch => axiosConfig.request({
export const updateProfile = updatedProfileInfo => dispatch => axiosConfigAuth.request({
method: 'put',
url: 'user/',
data: updatedProfileInfo,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/actions/articleActions.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from 'expect';
import promiseMiddleware from 'redux-promise-middleware';
import axiosconfig from '../../axiosConfig';
import { axiosConfigAuth } from '../../axiosConfig';
import moxios from 'moxios';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
Expand All @@ -16,10 +16,10 @@ describe('async actions', () => {
const middlewares = [promiseMiddleware()];

beforeEach(() => {
moxios.install(axiosconfig);
moxios.install(axiosConfigAuth);
});
afterEach(() => {
moxios.uninstall(axiosconfig);
moxios.uninstall(axiosConfigAuth);
});
it('it dispatches PERSONAL_ARTICLES_FETCHED on fetchPersonalArticles', () => {
const payload = { profile };
Expand Down
6 changes: 3 additions & 3 deletions src/tests/actions/profileActions.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from 'expect';
import promiseMiddleware from 'redux-promise-middleware';
import axiosconfig from '../../axiosConfig';
import { axiosConfigAuth } from '../../axiosConfig';
import moxios from 'moxios';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
Expand All @@ -16,10 +16,10 @@ describe('async actions', () => {
const middlewares = [promiseMiddleware()];

beforeEach(() => {
moxios.install(axiosconfig);
moxios.install(axiosConfigAuth);
});
afterEach(() => {
moxios.uninstall(axiosconfig);
moxios.uninstall(axiosConfigAuth);
});
it('it dispatches PROFILE_FETCHED on fetchProfile', () => {
const payload = { errors };
Expand Down

0 comments on commit 6bbfc7d

Please sign in to comment.