Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brandenwagner's avatar

Spark Vue. Broke CSRF.. But I don't know what I did

So i didnt change any of the JS. and i dont remember changing anything with CSRF.. But now anytime i load any page using Vue I get this error:

TypeError: undefined is not an object (evaluating 'request.headers.set')                exports App.js:35152

The exports function has this...

module.exports = function (request, next) { if (Cookies.get('XSRF-TOKEN') !== undefined) { request.headers.set('X-XSRF-TOKEN', Cookies.get('XSRF-TOKEN')); }

Any help is appreciated, im sure its simple, but ive been staring at it too long. This worked before i upgraded to spark 2.0.

0 likes
2 replies
philmartinez's avatar

I'm having the same issue. Were you able to figure this out? Thanks.

ejdelmonico's avatar

Here is my interceptors.js file:

module.exports = (request, next) => {

    if (Cookies.get('XSRF-TOKEN') !== undefined) {
        request.headers.set('X-XSRF-TOKEN', Cookies.get('XSRF-TOKEN'));
    }

    request.headers.set('X-CSRF-TOKEN', Spark.csrfToken);

    /**
     * Intercept the incoming responses.
     *
     * Handle any unexpected HTTP errors and pop up modals, etc.
     */
    next(response => {
        switch (response.status) {
            case 401:
                Vue.http.get('/logout');
                $('#modal-session-expired').modal('show');
                break;

            case 402:
                window.location = '/settings#/subscription';
                break;
        }

    });
};

Please or to participate in this conversation.