Netlify edge function, which password protects your site.
Netlify Edge Functions run in a secure runtime based on Deno.
The Netlify free pricing model does not include basic authentication headers to password protect your site.
- 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'
- Add the following part to your
netlify.toml
file-based configuration:
[[edge_functions]]
path = "/*"
function = "basic-auth"
- 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.
Please see the Netlify documentation to see how you can configure a custom edge functions folder.