Skip to content

Instantly share code, notes, and snippets.

@daffl
Created June 25, 2015 14:33
Show Gist options
  • Select an option

  • Save daffl/4e1389a3d16c82ff7233 to your computer and use it in GitHub Desktop.

Select an option

Save daffl/4e1389a3d16c82ff7233 to your computer and use it in GitHub Desktop.
Authentication for SocketIO and REST APIs
var app = feathers()
.configure(feathers.rest())
.configure(feathers.socketio(function(io) {
io.use(function(socket, next) {
socket.feathers.user = socket.request.session.user;
next();
});
}))
.use(function(req, res, next) {
req.feathers.user = req.session.user;
next();
})
.use('/todos', {
create: function(data, params, callback) {
if(!params.user || !params.user.isAdmin) {
return callback(new Error('You are not allowed to create Todos'));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment