I'm trying to check the username in the NodeJs chat with the user session. Is there a secure way to do it? (My NodeJs server isn't in the same place as the host of the website). I'm using this code NodeJs + express to do the chat application.
Code:
var express = require('express');
var app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server, { log: false });
server.listen(8080);
app.get('/chat.js', function(req, res) {
res.sendfile('chat.js');
});
/* CHAT FUNCTIONS */
io.sockets.on('connection', function (socket) {
socket.on('send', function (data) {
// I wanna get the user session
// something like this:
// (code below does not exist)
var username = session['username'];
console.log(username + " is here.");
io.sockets.emit('message', data);
});
});
How can I do this?