8
My main app is a Django app, however, for some realtime stuff, I want to use Node/Socket.IO. I'm using Redis to do some pub/sub from Django to Node (and then on to various clients). The tricky part is how do I authenticate the Node user against the Django auth?
In my Node app, I have:
io.on('connection', function (socket) {
const subscribe = redis.createClient();
var userId = authenticateAndGetUserId();
subscribe.subscribe(userId + ':feed-items');
subscribe.on('message', function (channel, message) {
socket.emit('feed-items', JSON.parse(message));
});
});
So my question is what's a good strategy for implementing authenticateAndGetUserId? The sessions are backed in MySQL, so I can go through there. Just curious if there's a better way to go about it.