node.js - Browser not sending back cookies, but curl does -
i developing nodejs application scratch. beginning play node. building login system, found issue:
when login correct name , password, cookie set 'remember_token' value. supposed store user session. cookies in google chrome browser
the cookie set correctly, when browser makes new request, cookie value not set in server:
when make request trhoug curl, cookies recieved server:
curl -i 'http://localhost' -b "remember_token=znvuy3rpb24gbm93kckgeybbbmf0axzlignvzgvdih0wlja1ntg2mzu1mtu2mjy1mtk5"
aditional info
i added lines app.js before middleware called:
app.use(function(req, res, next){ console.log('\nrequest: ' + json.stringify(req.headers)); next(); });
and output when make request browser:
request: {"host":"node","connection":"close","cache-control":"max-age=0","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","user-agent":"mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.95 safari/537.36","referer":"http://localhost/","accept-encoding":"gzip,deflate,sdch","accept-language":"es-419,es;q=0.8,en;q=0.6,en-au;q=0.4,en-ca;q=0.2,en-us;q=0.2,en-nz;q=0.2,en-gb;q=0.2,en-za;q=0.2","cookie":"connect.sid=s%3ab8g0vgivuiuot4a9dkl3wmfu.625hfc6w4timujyk4x9clfena0fi8pd%2fdmg0sspaw5e","if-none-match":"\"-651269513\""}
no remember token cookie on header. tested in: google chrome, chromium , mozilla firefox. why this?
update
this how create cookies:
exports.identificar = function (req, res, success, fail) { var remember_token = null; var u; usuarios.findbyemail(req.body.sesion.email,function(usuario){ if (usuario) { crypt.comparepassword(req.body.sesion.password, usuario.password_digest, function(err, resp) { if (err) { fail('hubo un error de encripciĆ³n'); } else if (resp) { remember_token = usuario.remember_token; u = usuario.tojson(); delete u['password_digest']; delete u['remember_token']; delete u['fecha_token']; delete u['token']; if (typeof req.body.sesion.recordar !== "undefined"){ res.cookie('remember_token', remember_token, {expires: new date(date.now() + 900000), secure: true}); } else { res.cookie('remember_token', remember_token, {secure: true}); } req.session.usuario = u; success(u); } else { fail('contraseƱa incorrecta'); } }); } else { fail('usuario no encontrado'); } }); };
solved
i solved removing "secure:true" option in server when set cookie, but. why did happen?
the secure option secure connections, had remove "secure:true" flag on server when set cookie.
Comments
Post a Comment