npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deployment-protector

v0.3.3

Published

Put a very simple password lock ok your Next.js v15 deployment(s).

Downloads

470

Readme

Deployment Protector

Put a very simple password lock ok your Next.js v15 deployment(s).

This will not protect you from code and content leaks by any means unlike Vercel's own deployment protection. It's a very basic form of protection that doesn't work on infrastructure level.

I needed this because I needed to hide the contents of one of my smaller projects on a production domain as well so I decided to build something that can do the job on a very basic level.

Usage

Install:

$ pnpm add deployment-protector

Create two environment variables to store:

  • DP_SECRET_KEY - the JWT secret
  • DP_PASSWORD the password that will be used to auth the users

Consume the component in your root layout.tsx (or any other layout.tsx, for that matter):

//...
import DeploymentProtector from 'deployment-protector';
//...

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={`${geistSans.variable} ${geistMono.variable}`}>
        <DeploymentProtector>
          {children}
        </DeploymentProtector>
      </body>
    </html>
  );
}

Configuration

Check the props that are exposed on DeploymentProtector.

Known issues

Weird type mismatch could happen although DeploymentProtector is a valid React component and you might get:

Type 'bigint' is not assignable to type 'AwaitedReactNode'.ts(2786)

I suspect this is due to typing issues in React 19 or Next.js something (see this and this). If you run into it just put a @ts-expect-error on it or open up an issue/PR if you know how to resolve this.

How it works etc

It loads up and runs a single server component that performs the followint checks:

  • is the cookie there -> yes, does it contain a valid JWT ->yes, render children elements
  • else render the login form and bind it to a server action that validates against the password and sets a JWT as a cookie

Maybe this would work better if it was implemented on a middleware level? Maybe I'll revisit it in the future and see about this.