How to refresh headers with token for fullcalendar AJAX requests

688 views Asked by At

I'm sending token headers under eventSources option for "full calender" with below headers option in Angular:

eventSources: [
    {
        url: '/api/schedules',
        headers: JSON.parse($cookies['auth_headers']),
        error: function () {
            var $state = $injector.get('$state');
            $state.transitionTo('page.login');
        }
    }
],

Given fullcalendar uses jQuery, I need to have headers refreshed for every request. Is there a way to do this with fullcalendar?

1

There are 1 answers

2
AlliterativeAlice On

Untested, but specifying a beforeSend function should make this possible:

eventSources: [
    {
        url: '/api/schedules',
        beforeSend: function(xhr) {
            var headers = JSON.parse($cookies['auth_headers']);
            for (var i in headers ) xhr.setRequestHeader(i, headers[i]);
        },
        error: function () {
            var $state = $injector.get('$state');
            $state.transitionTo('page.login');
        }
    }
],