Wondering what’s next for npm?Check out our public roadmap! »

    nghiepit-test
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.8 • Public • Published

    next-universal-cookie

    NPM version NPM monthly download

    A set of cookie helpers for Next.js similar to express such as req.cookies, res.cookie and res.clearCookie

    Installation

    yarn add 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
      const cookies = req.cookies;
    
      // Set
      res.cookie();
    
      // Destroy
      res.clearCookie();
    
      return {
        props: {},
      };
    };
    
    Home.getInitialProps = ({req, res}: NextPageContext) => {
      applyServerSideCookie(req, res);
    
      // Typescript-ready
      req.cookies;
      res.cookie();
      res.clearCookie();
    
      return {};
    };

    API Routes

    // pages/api/index.ts
    import {NextApiRequest, NextApiResponse} from 'next';
    import {applyApiCookie} from 'next-universal-cookie';
    
    export default (req: NextApiRequest, res: NextApiResponse) => {
      applyApiCookie(req, res);
    
      // Typescript-ready
      req.cookies;
      res.cookie();
      res.clearCookie();
    };

    API

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

    License

    MIT

    Install

    npm i nghiepit-test

    DownloadsWeekly Downloads

    58

    Version

    0.0.8

    License

    MIT

    Unpacked Size

    7.91 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar