Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2013 00:37
Show Gist options
  • Save anonymous/5408941 to your computer and use it in GitHub Desktop.
Save anonymous/5408941 to your computer and use it in GitHub Desktop.
// Make sure the socket is coming from our app by matching the session id
socketServer.set('authorization', function (data, accept) {
cookieParser(data, {}, function(err) {
if (err) {
accept(err, false);
} else {
config.sessionStore.load(data.signedCookies[config.sessionKey], function(err, session) {
if (err || !session) {
accept('Session error', false);
} else {
data.session = session;
accept(null, true);
}
});
}
});
});
// Set up an admin channel that checks for admin authorization
socketServer.of('/admin').authorization(function (data, accept) {
cookieParser(data, {}, function(err) {
if (err) {
accept(err, false);
} else {
config.sessionStore.load(data.signedCookies[config.sessionKey], function(err, session) {
if (!session.uid) {
accept('Access denied', false);
} else {
Users.findOne({_id: session.uid}, function (err, db_user) {
if (db_user && db_user.name == 'admin') {
accept(null, true);
} else {
accept('Access denied', false);
}
});
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment