Note that there are some explanatory texts on larger screens.

plurals
  1. POreq.signedCookies not being read in expressJS
    primarykey
    data
    text
    <p>This is my setup: </p> <p>express.js version": "3.0.0rc2" </p> <p><strong><code>app.js</code></strong></p> <pre><code>... app.use(express.cookieParser('secret')); app.use(express.session({secret: 'secret'})); app.use(app.router); ... </code></pre> <p>Then to set the signed cookie and a redirect:<br> <code>res.cookie('session', cookie_value, {signed: true});</code> <code>res.redirect('/else_where');</code></p> <p>Then to retrieve the signed cookie:<br> <code>var cookie = req.signedCookies.session;</code> </p> <pre><code>console.log('get cookie: ' + req.cookies.session); console.log('get signed cookie: ' + req.signedCookies.session); </code></pre> <p>The problem is that the cookie is <code>undefined</code> for the signed cookie and works fine with the <code>req.cookies.session</code>.</p> <p>For some reason I the signing of the cookie is not being played out.<br> Not sure what's going on.<br> Is the order of my <code>app.use()</code> correctly laid out?</p> <p>similar to this <a href="https://stackoverflow.com/questions/11897965/what-are-signed-cookies-in-connect-expressjs">this</a></p> <p><strong>UPDATE_02</strong><br> I implemented a simple <code>res/req</code> for a signed cookie like so:</p> <pre><code>app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.cookieParser('secret')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(expressValidator); app.use(express.session()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); }); app.get('/', function(req, res) { if (!req.signedCookies.cat) { res.cookie('cat', 'boo', {signed: true}); console.log('setting cookie'); res.writeHead(200, {'Content-Type':'text/plain'}); return res.end('cookie set'); } res.end('signed cookie: ' + req.signedCookies.cat); }); </code></pre> <p>When I use the browser to hit <code>localhost:3000</code> I get the first desired response<code>cookie set</code>.<br> I check the browser cookies and the cookie has been set.<br> When I use the same browser to hit <code>localhost:3000</code> again I get the same response 'cookie set'.<br> The request does not seem to pickup on the cookie. </p> <p>So in another file I copied/paste the exact above code and switched ports to <code>3080</code>.<br> When that goes through the second response produces `signed cookie: boo'. </p> <p>Then if I refresh <code>localhost:3000</code> the response is <code>signed cookie: boo</code>.<br> Why does this happen? Is there caching going on that shouldn't?<br> Any help is appreciated.</p> <p><strong>UPDATE_01</strong><br> Even if I do a <code>req.signedCookies.session</code> immediately after setting the cookie I get back <code>undefined</code>. The cookie does get signed because there is an additional <code>.</code> followed by a bunch of random letters and numbers. It's not being assigned to <code>req.signedCookies</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload