Skip to content

acestojanoski/netlify-basic-auth-edge-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

netlify-basic-auth-edge-function

Netlify edge function, which password protects your site.

Netlify Edge Functions run in a secure runtime based on Deno.

Motivation

The Netlify free pricing model does not include basic authentication headers to password protect your site.

Usage

  1. Create netlify/edge-functions/basic-auth.ts file in your repository:

Replace LATEST_VERSION with the latest version.

// netlify/edge-functions/basic-auth.ts

export { handler as default } from 'https://deno.land/x/netlify_basic_auth_edge_function@LATEST_VERSION/mod.ts'
  1. Add the following part to your netlify.toml file-based configuration:
[[edge_functions]]
    path = "/*"
    function = "basic-auth"
  1. Set the following environment variable in Netlify settings to configure basic authentication:
  • BASIC_AUTH_CREDENTIALS - space delimited USERNAME:PASSWORD list.

    Example: john:strongpass1 johny:strongpass2

NOTE: If the environment variable is not set, the edge function will continue without authentication.

IMPORTANT: We recommend rotating your passwords periodically.

Custom edge functions folder

Please see the Netlify documentation to see how you can configure a custom edge functions folder.

About

Netlify edge function, which password protects your site.

Resources

License

Stars

Watchers

Forks

Packages

No packages published