New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

electrode-cookies

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrode-cookies

Electrode ISO cookies lib

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Electrode Cookies

Electrode isomorphic cookies lib.

Install

npm install electrode-cookies --save

Usage

This module offers reading and setting cookies in React code that works in both the browser or when doing Server Side Rendering.

In your pure server only code, you can also use this module to read and set cookies, but you MUST pass the request object in the options. Otherwise an assert error will be thrown.

In NodeJS land:

const Cookies = require("electrode-cookies");

Reading cookies

In ReactJS land:

import Cookies from "electrode-cookies";
const value = Cookies.get("test-cookie");

In NodeJS land:

Note the difference is that request is passed in options.

const Cookies = require("electrode-cookies");
const value = Cookies.get("test-cookie", { request });

Writing cookies

In ReactJS land:

import Cookies from "electrode-cookies";
Cookies.set( "foo", "bar", { path: "/", domain: ".walmart.com" } );

In NodeJS land:

Note the difference is that request is passed in options.

const Cookies = require("electrode-cookies");
Cookies.set( "foo", "bar", { request, path: "/", domain: ".walmart.com" } );

Electrode Server Setup

The cookie writing on server side requires support from a Hapi plugin. If you use electrode-server, then it should have setup the plugin for you by default. Otherwise, you need to register the hapi plugin.

APIs

Cookies.get

Cookies.get(key, [options])

Parameters:

  • key - name of the cookie
  • options - (optional) Available for Server side only. options for getting the cookie
    • request - The server request object (Required on server).
    • matchSubStr - If true, then do substring matching of key with all cookie keys.
      • skipEncoding - (applies only if matchSubStr is true) If true, then do not encode the key or decode the value.

Returns the value of the cookie for key.

Cookies.set

Cookies.set(key, value, [options])

Set a cookie with key and value.

Parameters:

  • key - name of the cookie
  • value - value of the cookie
  • options - (optional) options for the cookie
    • request - On the server side, the request object (Required on server).
    • path - string path of the cookie Default: "/"
    • domain - string domain of the cookie
    • expires - number of seconds the cookie will expire
    • secure - A boolean of whether or not the cookie should only be available over SSL Default: false
    • httpOnly - A boolean of whether or not the cookie should only be available over HTTP(S) Default: false
    • forceAuthEncoding - Forces non-standard encoding for + and / characters, use with auth cookies.
    • skipEncoding - Skip encoding/escaping of the cookie value. See source for details.

Cookies.expire

Cookies.expire(key, [options])

Expires a cookie specified by key.

Parameters:

  • key - name of the cookie
  • options - (optional) options for the cookie
    • path - string path of the cookie Default: "/"
    • domain - string domain of the cookie
    • secure - A boolean of whether or not the cookie should only be available over SSL Default: false
    • request - The server request object (Required on server)

FAQs

Package last updated on 07 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc