How to add Basic-Auth to sections of a (docusaurus) site


I have a site built on docusaurus which I have hosted on AWS Amplify for a while but switched to Netlify mostly because of the flexible auth functions.

I would like to add basic-auth to my site, but rather than at the site level i would like to have it on certain sun folders.

I have been reading for hours and am obviously missing something obvious! It seems I need to add a _header file to my publish directory? Which I assume is handled by the build script? If so where does one store the credentials for the build script to access? And I assume that on each deploy a new _header file will be created, so we must require a static storage of the _header file contents

I store my site on GitHub so don’t want to put credentials there!

Hi @ClubmanPlus850,

If you don’t wish to store the credentials directly in the _headers file, you’d have to generate one during the build. You can store the password in environment variables and use something like Node.js writeFileSync() to create a _headers file or even use bash scripting to achieve that.

The structure of the file should be something like: