@@ -4,11 +4,12 @@ import cookie from 'react-cookie';
44const API_URL = `${ window . location . origin } /api/v1/holidays` ;
55
66const headers = { } ;
7- headers [ 'Authorization' ] = `Bearer ${ cookie . load ( 'token' ) } ` ;
7+
88
99export 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() {
2526export 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) {
4244export 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) {
5760export 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) {
7377export 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 } ) ;
0 commit comments