Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

netlify-plugin-redirect-with-auth

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netlify-plugin-redirect-with-auth

Add redirects with authorization header set in env variable

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
0
Weekly downloads
 
Created
Source

Netlify Plugin: Redirect with Auth

This Netlify build plugin allows you to add redirects with authentication headers to your Netlify site.

Features

  • Adds redirects with custom authentication headers - header is set in an environment variable, separate from the code in your repo
  • Works for both build and development environments
  • Configurable through the netlify.toml file

Installation

  1. First, install the plugin as an npm dependency:
npm install netlify-plugin-redirect-with-auth
  1. Then, add the plugin to your netlify.toml file:
[[plugins]]
package = "netlify-plugin-redirect-with-auth"

  [plugins.inputs]
  redirects = [
    { from = "/submit", to = "https://api.example.com/submit" },
    { from = "/api/*", to = "https://api.example.com/:splat" }
 ]
  1. Set the NETLIFY_REDIRECT_AUTH_HEADER environment variable:

    For production:

    • Go to your Netlify site dashboard
    • Navigate to Site settings > Build & deploy > Environment
    • Add a new environment variable:
      • Key: NETLIFY_REDIRECT_AUTH_HEADER
      • Value: Your desired authorization header (e.g., Bearer your-token-here)

    For development:

    • Create a .env file in your project root (if it doesn't exist already)
    • Add the following line to the .env file:
      NETLIFY_REDIRECT_AUTH_HEADER=Bearer your-token-here
      
    • This environment variable will be used when you run netlify dev

Note: Make sure to add .env to your .gitignore file to avoid committing sensitive information to your repository.

Configuration

Environment Variables

Set the following environment variable in your Netlify site settings:

  • NETLIFY_REDIRECT_AUTH_HEADER: The authentication header to be added to the redirects.

Plugin Inputs

Configure the plugin in your netlify.toml file:

[[plugins]]
package = "netlify-plugin-redirect-with-auth"

  [plugins.inputs]
  redirects = [
    { from = "/submit", to = "https://api.example.com/submit" },
    { from = "/api/*", to = "https://api.example.com/:splat" }
  ]

Each redirect object in the redirects array must have both from and to properties.

How It Works

  1. The plugin runs during the onPreBuild and onPreDev events.
  2. It checks for the presence of the NETLIFY_REDIRECT_AUTH_HEADER environment variable.
  3. It validates the redirects input to ensure it's a non-empty array of valid redirect objects.
  4. For each redirect, it adds a new redirect rule to the Netlify configuration with:
    • The specified from and to URLs
    • A status code of 200
    • The force flag set to true
    • The authentication header from the environment variable

Notes

  • This plugin adds the authentication header to all specified redirects.
  • The redirects are set to force (always redirect, even if the requested file exists).
  • The status code is set to 200 for all redirects.

Troubleshooting

If you encounter issues:

  1. Ensure the NETLIFY_REDIRECT_AUTH_HEADER environment variable is set correctly.
  2. Check that your redirects input in netlify.toml is formatted correctly.
  3. Verify that each redirect object has both from and to properties.

For more help, please open an issue in the plugin's GitHub repository.

Keywords

FAQs

Package last updated on 11 Aug 2024

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