I'm using Restify module to create REST server and using Restify-session module to save user credentials. However, I cannot seem to retrieve save session data. My request object does not have session data I saved earlier. I tried 'load' method of session object and data parameter of the callback function and it only contains SID. And seems that Restify does not have much resources online. I couldn't find much online. I appreciate much if anyone can point me to the right direction. This is my attempt
restify = require('restify'),
session = require('restify-session')({
debug : false,
ttl : 60 // Time to live in seconds
});
server = restify.createServer();
server.use(session.sessionManager);
server.listen(8001);
server.post('/session', start);
server.post('/homepage', loadHomePage);
function start(req, res, next) {
var data = {user: req.query.credential}; // Base-64 encoding of username and password
session.save(req.session.sid, data, function(err, status){
if(err) {
console.log("Session data cannot be saved");
return;
}
console.log("status-" + status + data.user); //debug code
});
function loadHomePage(req, res, next) {
session.load(req.session.sid,function(err,data){
if(err) {
res.writeHead(440, 'Login Time Out', {'Content-Type': 'application/json'});
res.end("{'Status': 'Error', 'Message': 'Session expired or does not exist'}");
return;
}
for(var n in data) { // Checking what properties data has
console.log(n); // Shows only SID value
}
});
UPDATE : I found out what's going out. Restify-Session is generating new session id for every request. That's why I cannot find saved data. But I'm not sure how to resolve this issue.