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
});