How to use the cookie.serialize function in cookie

To help you get started, we’ve selected a few cookie 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 Widen / cloudfront-auth / authn / openid.index.js View on Github external
{ },
                          config.PRIVATE_KEY.trim(),
                          {
                            "audience": headers.host[0].value,
                            "subject": auth.getSubject(decodedData),
                            "expiresIn": config.SESSION_DURATION,
                            "algorithm": "RS256"
                          } // Options
                        ), {
                          path: '/',
                          maxAge: config.SESSION_DURATION
                        })
                      },
                      {
                        "key": "Set-Cookie",
                        "value" : cookie.serialize('NONCE', '', {
                          path: '/',
                          expires: new Date(1970, 1, 1, 0, 0, 0, 0)
                        })
                      }
                    ],
                  },
                };
                callback(null, response);
              } else {
                unauthorized('Nonce Verification Failed', '', '', callback);
              }
            }
          });
        } catch (error) {
github nuxt-community / universal-storage-module / lib / storage.js View on Github external
setCookie (key, value, options = {}) {
    if (!this.options.cookie) {
      return
    }

    const _key = this.options.cookie.prefix + key
    const _options = Object.assign({}, this.options.cookie.options, options)
    const _value = encodeValue(value)

    const serializedCookie = serializeCookie(_key, _value, _options)

    if (process.client) {
      // Set in browser
      document.cookie = serializedCookie
    } else if (process.server && this.ctx.res) {
      // Send Set-Cookie header from server side
      this.ctx.res.setHeader('Set-Cookie', serializedCookie)
    }

    return value
  }
github zeit / next.js / examples / with-apollo-auth / components / SigninBox.js View on Github external
const onCompleted = data => {
    // Store the token in cookie
    document.cookie = cookie.serialize('token', data.signinUser.token, {
      sameSite: true,
      path: '/',
      maxAge: 30 * 24 * 60 * 60, // 30 days
    })
    // Force a reload of all the current queries now that the user is
    // logged in
    client.cache.reset().then(() => {
      redirect({}, '/')
    })
  }
github Opentrons / opentrons / protocol-designer / src / networking / opentronsWebApi.js View on Github external
const writeIdentityCookie = payload => {
  const domain =
    process.env.NODE_ENV === 'production' ? 'opentrons.com' : undefined
  global.document.cookie = cookie.serialize('ot_name', payload.name, {
    domain,
    maxAge: 10 * 365 * 24 * 60 * 60, // 10 years
  })
  global.document.cookie = cookie.serialize('ot_email', payload.email, {
    domain,
    maxAge: 10 * 365 * 24 * 60 * 60, // 10 years
  })
}
github joshlobaptista / Barista-Fullstack / node_modules / express / lib / response.js View on Github external
: String(value);

  if (signed) {
    val = 's:' + sign(val, secret);
  }

  if ('maxAge' in opts) {
    opts.expires = new Date(Date.now() + opts.maxAge);
    opts.maxAge /= 1000;
  }

  if (opts.path == null) {
    opts.path = '/';
  }

  this.append('Set-Cookie', cookie.serialize(name, String(val), opts));

  return this;
};
github Automattic / wp-calypso / client / lib / oauth-token / index.js View on Github external
export function clearToken() {
	const cookies = cookie.parse( document.cookie );

	if ( typeof cookies[ TOKEN_NAME ] !== 'undefined' ) {
		document.cookie = cookie.serialize( TOKEN_NAME, false, { maxAge: -1 } );
	}
}
github mike-engel / styled-typography / packages / dubdubdub / components / hocs / theme_manager.component.tsx View on Github external
useEffect(() => {
		if (typeof window !== "undefined") {
			const setCookie = cookie.serialize("theme", theme);

			document.cookie = setCookie;
		}
	}, [theme]);
github Widen / cloudfront-auth / index.js View on Github external
"state": request.uri,
    "response_type": "code"
  });

  const response = {
    status: '302',
    statusDescription: 'Found',
    body: 'Authenticating with Google',
    headers: {
        location : [{
            key: 'Location',
            value: discoveryDocument.authorization_endpoint + "?" + querystring
         }],
         'set-cookie' : [{
           key: 'Set-Cookie',
           value : cookie.serialize('TOKEN', '', { path: '/', expires: new Date(1970, 1, 1, 0, 0, 0, 0) })
         }],
    },
  };
  callback(null, response);
}
github botsail / botsailce / app / controllers / bsadmin.js View on Github external
proccess.update(urlupdate, '/', function(){

				res.setHeader("Set-Cookie", [
						Cookie.serialize('cbv', req.query.v, {
						expires: new Date(Date.now() + 900000),
						path: '/'
					}),
				  		Cookie.serialize('cbu', true, {
						expires: new Date(0),
						path: '/'
					})]);

				res.send('success');
			});
		}else{
github maticzav / nookies / src / index.ts View on Github external
parsedCookies.forEach((parsedCookie: Cookie) => {
      if (!areCookiesEqual(parsedCookie, createCookie(name, value, options))) {
        cookiesToSet.push(
          cookie.serialize(parsedCookie.name, parsedCookie.value, {
            domain: parsedCookie.domain,
            path: parsedCookie.path,
            httpOnly: parsedCookie.httpOnly,
            secure: parsedCookie.secure,
            maxAge: parsedCookie.maxAge,
            expires: parsedCookie.expires,
          }),
        )
      }
    })