Sails.js - Using satellizer's interceptor with io.socket requests for adding an authorization header

491 views Asked by At

So I am learning right now the Sails.js framework and more specifically it's socket functionalities. For my frontend which is separated from the sails backend (API), I use AngularJS with sails.io.js and for user authentication I am using satellizer. So satellizer gives me already a nice ready functionally that I don't have to write. Like it's interceptor which adds an authorization header to each request to the API.

The problem is - when I use io.socket request like:

// Won't send authorization header to the backend
io.socket.post(url, params, function(data, res) {
    // handle response
});

The authorization header is not set by the interceptor. I have to do that manually with io.socket.request like that:

// Sends authorization header to the backend
io.socket.post({
    url: someUrl,
    method: 'POST',
    headers: {
        authorization: 'Bearer ' + $auth.getToken()
    },
    params: {
        // someParams
    }
}, function(data, res) {
    // handle response
});
0

There are 0 answers