Skip to content

Commit 582d096

Browse files
committed
auth_headers_fix
1 parent f2977ec commit 582d096

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

client/src/actions/auth.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ export function login(data, router) {
6767
.then((res) => {
6868
if (res && res.status == 200) {
6969
const { data } = res;
70-
70+
71+
saveAuthToken(data);
72+
7173
dispatch({
7274
type: LOGIN_SUCCESS,
7375
payload: {
7476
token: data.access_token
7577
}
7678
});
7779

78-
saveAuthToken(data);
7980
new Toaster(dispatch).success('Login successfully');
80-
dispatch(push('/registers'));
81+
browserHistory.push('/registers');
8182
}
8283
})
8384
.catch(err => {

client/src/actions/features.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import cookie from 'react-cookie'
44
const API_URL = `${window.location.origin}/api/v1/features`
55

66
let headers = {}
7-
headers['Authorization'] = `Bearer ${cookie.load('token')}`
87

98
export function show() {
109
return function(dispatch, getState) {
1110
return new Promise((resolve, reject) => {
1211
let currentWorkspace = cookie.load('current_workspace')
1312
let { id } = currentWorkspace
1413

14+
headers['Authorization'] = `Bearer ${cookie.load('token')}`
1515
headers['workspace-id'] = id
1616

1717
axios.get(`${API_URL}/${id}`, { headers })

client/src/actions/holidays.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import cookie from 'react-cookie';
44
const API_URL = `${window.location.origin}/api/v1/holidays`;
55

66
const headers = {};
7-
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
7+
88

99
export function index() {
1010
return function(dispatch, getState) {
1111
return new Promise((resolve, reject) => {
12+
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
1213
axios.get(API_URL)
1314
.then(res => {
1415
dispatch({ type: 'FETCH_HOLIDAY_ITEMS', payload: res.data });
@@ -25,6 +26,7 @@ export function index() {
2526
export function create(item) {
2627
return function(dispatch, getState) {
2728
return new Promise((resolve, reject) => {
29+
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
2830
axios.post(API_URL, item, { headers })
2931
.then(res => {
3032
item.id = res.data
@@ -42,6 +44,7 @@ export function create(item) {
4244
export function update(item, id) {
4345
return function(dispatch, getState) {
4446
return new Promise((resolve, reject) => {
47+
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
4548
axios.patch(`${API_URL}/${id}`, item, { headers: headers })
4649
.then(res => {
4750
resolve(res);
@@ -57,6 +60,7 @@ export function update(item, id) {
5760
export function destroy(id) {
5861
return function(dispatch, getState) {
5962
return new Promise((resolve, reject) => {
63+
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
6064
axios.delete(`${API_URL}/${id}`, { headers: headers })
6165
.then(res => {
6266
dispatch({ type: 'DESTROY_HOLIDAY_ITEM', payload: id });
@@ -73,6 +77,7 @@ export function destroy(id) {
7377
export function show(id) {
7478
return function(dispatch, getState) {
7579
return new Promise((resolve, reject) => {
80+
headers['Authorization'] = `Bearer ${cookie.load('token')}`;
7681
axios.get(`${API_URL}/${id}`, { headers: headers })
7782
.then(res => {
7883
dispatch({ type: 'FETCH_HOLIDAY_ITEM', payload: res.data });

client/src/actions/inventory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import cookie from 'react-cookie'
44
const API_URL = `${window.location.origin}/api/v1/inventory_items`
55

66
let headers = {}
7-
headers['Authorization'] = `Bearer ${cookie.load('token')}`
87

98
if (cookie.load('current_workspace')) {
109
headers['workspace-id'] = cookie.load('current_workspace').id
@@ -13,6 +12,7 @@ if (cookie.load('current_workspace')) {
1312
export function index() {
1413
return function(dispatch, getState) {
1514
return new Promise((resolve, reject) => {
15+
headers['Authorization'] = `Bearer ${cookie.load('token')}`
1616
headers['workspace-id'] = cookie.load('current_workspace').id
1717
axios.get(API_URL, { headers })
1818
.then(res => {

0 commit comments

Comments
 (0)