New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details → →
Socket
Book a DemoSign in
Socket

next-universal-cookie

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-universal-cookie

🍪 Provides way to read, set and delete a cookie for Next.js

latest
Source
npmnpm
Version
3.1.0
Version published
Maintainers
1
Created
Source

NPM version NPM monthly download

Provides way to read, set and delete a cookie for Next.js similar to express such as req.cookies, res.cookie and res.clearCookie

Installation

npm install next-universal-cookie

Usage

With getServerSideProps and getInitialProps

import {GetServerSideProps, NextPageContext} from 'next';
import {applyServerSideCookie} from 'next-universal-cookie';

export const getServerSideProps: GetServerSideProps = async ({req, res}) => {
  applyServerSideCookie(req, res);

  // Typescript-ready

  // Parse all cookies
  const allCookies = req.cookies;

  // Set
  res.cookie();

  // Delete
  res.clearCookie();

  return {
    props: {},
  };
};

API Routes

// pages/api/index.ts
import {NextApiRequest, NextApiResponse} from 'next';
import {applyApiCookie} from 'next-universal-cookie';

export default function handler(
  req: NextApiRequest,
  res: NextApiResponse<{ok: boolean}>
) {
  applyApiCookie(req, res);

  // Typescript-ready
  const allCookies = req.cookies;
  res.cookie();
  res.clearCookie();

  // Response
  res.json({
    ok: true,
  });
}

API

import {applyServerSideCookie, applyApiCookie} from 'next-universal-cookie';

License

MIT

Keywords

cookie

FAQs

Package last updated on 22 Jun 2022

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