🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

next-headers

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

next-headers

A Next.js plugin to access headers() and cookies() in the middleware

0.0.5
latest
npm
Version published
Weekly downloads
55
-49.54%
Maintainers
1
Weekly downloads
 
Created
Source

next-headers

A (very) tiny wrapper to allow you to use Next.js's cookies() and headers() functions in your middleware.

publish size Tree shaking supported

Why would I need this?

Next.js's cookies() and headers() functions are only available in app directory. This means that if you want to use them in your middleware, you need to pass the request object from your middleware to every function down the stream. This can get messy, especially if you have multiple layers of middlewares, or if you have shared logic between your middleware and server code.

Warning

This plugin works only from next@13.4.4 ! If you are using an older version, please upgrade.

Installation

npm

npm install next-headers

Yarn

yarn add next-headers

Usage

Open your middleware.ts file and import the next-headers package:

import { withNextHeaders } from "next-headers";

Then, wrap your middleware with the withNextHeaders function:

export const middleware = withNextHeaders((request) => {
  // You can now use cookies() and headers() here
});

That's it! You can now use cookies() and headers() in your middleware.

FAQs

Package last updated on 11 Jul 2023

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