How to use the cookie-parser.JSONCookie function in cookie-parser

To help you get started, we’ve selected a few cookie-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodesocket / quote-stream / node_modules / express / node_modules / connect / lib / middleware / cookieSession.js View on Github external
// pathname mismatch
    var originalPath = parseUrl.original(req).pathname;
    if (0 != originalPath.indexOf(cookie.path)) return next();

    // cookieParser secret
    if (!options.secret && req.secret) {
      req.session = req.signedCookies[key] || {};
      req.session.cookie = cookie;
    } else {
      // TODO: refactor
      var rawCookie = req.cookies[key];
      if (rawCookie) {
        var unsigned = cookieParser.signedCookie(rawCookie, secret);
        if (unsigned) {
          var original = unsigned;
          req.session = cookieParser.JSONCookie(unsigned) || {};
          req.session.cookie = cookie;
        }
      }
    }

    onHeaders(res, function(){
      // removed
      if (!req.session) {
        debug('clear session');
        cookie.expires = new Date(0);
        res.setHeader('Set-Cookie', cookie.serialize(key, ''));
        return;
      }

      delete req.session.cookie;
github ifgyong / demo / React-native / Helloword / node_modules / connect / lib / middleware / cookieSession.js View on Github external
// pathname mismatch
        var originalPath = parseUrl.original(req).pathname;
        if (0 != originalPath.indexOf(cookie.path)) return next();

        // cookieParser secret
        if (!options.secret && req.secret) {
            req.session = req.signedCookies[key] || {};
            req.session.cookie = cookie;
        } else {
            // TODO: refactor
            var rawCookie = req.cookies[key];
            if (rawCookie) {
                var unsigned = cookieParser.signedCookie(rawCookie, secret);
                if (unsigned) {
                    var original = unsigned;
                    req.session = cookieParser.JSONCookie(unsigned) || {};
                    req.session.cookie = cookie;
                }
            }
        }

        onHeaders(res, function () {
            // removed
            if (!req.session) {
                debug('clear session');
                cookie.expires = new Date(0);
                res.setHeader('Set-Cookie', cookie.serialize(key, ''));
                return;
            }

            delete req.session.cookie;
github jonniespratley / jps-passbook-manager / node_modules / grunt-contrib-connect / node_modules / connect / lib / middleware / cookieSession.js View on Github external
// pathname mismatch
    var originalPath = parseUrl.original(req).pathname;
    if (0 != originalPath.indexOf(cookie.path)) return next();

    // cookieParser secret
    if (!options.secret && req.secret) {
      req.session = req.signedCookies[key] || {};
      req.session.cookie = cookie;
    } else {
      // TODO: refactor
      var rawCookie = req.cookies[key];
      if (rawCookie) {
        var unsigned = cookieParser.signedCookie(rawCookie, secret);
        if (unsigned) {
          var original = unsigned;
          req.session = cookieParser.JSONCookie(unsigned) || {};
          req.session.cookie = cookie;
        }
      }
    }

    onHeaders(res, function(){
      // removed
      if (!req.session) {
        debug('clear session');
        cookie.expires = new Date(0);
        res.setHeader('Set-Cookie', cookie.serialize(key, ''));
        return;
      }

      delete req.session.cookie;
github senchalabs / connect / lib / middleware / cookieSession.js View on Github external
// pathname mismatch
    var originalPath = parseUrl.original(req).pathname;
    if (0 != originalPath.indexOf(cookie.path)) return next();

    // cookieParser secret
    if (!options.secret && req.secret) {
      req.session = req.signedCookies[key] || {};
      req.session.cookie = cookie;
    } else {
      // TODO: refactor
      var rawCookie = req.cookies[key];
      if (rawCookie) {
        var unsigned = cookieParser.signedCookie(rawCookie, secret);
        if (unsigned) {
          var original = unsigned;
          req.session = cookieParser.JSONCookie(unsigned) || {};
          req.session.cookie = cookie;
        }
      }
    }

    onHeaders(res, function(){
      // removed
      if (!req.session) {
        debug('clear session');
        cookie.expires = new Date(0);
        res.setHeader('Set-Cookie', cookie.serialize(key, ''));
        return;
      }

      delete req.session.cookie;

cookie-parser

Parse HTTP request cookies

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis