Socket
Socket
Sign inDemoInstall

@phntms/next-basic-auth

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phntms/next-basic-auth

Lightweight middleware to add basic-auth protection onto your Next.js site.


Version published
Weekly downloads
3
Maintainers
2
Weekly downloads
 
Created
Source

next-basic-auth

NPM version Actions Status PR Welcome

Lightweight middleware to add basic-auth protection onto your Next.js site.

Introduction

Do you have a site that is still in development or need to protect non production environments? Then this basic library is for you. It allows you to protect all your pages in one go by adding this middleware to your _document template.

Installation

Install this package with npm.

npm i @phntms/next-basic-auth

Usage

import basicAuth from "@phntms/next-basic-auth";
import Document, {
  DocumentContext,
  Head,
  Html,
  Main,
  NextScript,
} from "next/document";

const authConfig = {
  name: "john",
  pass: "letmein",
  message: "Go away!",
};

export default class MyDocument extends Document {
  static async getInitialProps(ctx: DocumentContext) {
    await basicAuth(ctx, authConfig);
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

basicAuth Arguments

  • ctx : Required - The DocumentContext provided by getInitialProps.
  • config : Optional - BasicAuthMiddlewareConfig object which allows you to change the default configuration.

Configuration

You can override the configuration using these options...

  • name : The username required for login, defaults to admin.
  • pass : The password required for login, defaults to password.
  • realm : The realm used for the basic-auth, defaults to site.
  • message : The message to show upon unsuccessful login, defaults to 401 Access Denied.

Keywords

FAQs

Package last updated on 13 Jun 2021

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