Password protect your spacebook
By default, your spacebook is set up to be non-discoverable but you can also protect your entire site behind a password. When you enable, your entire site will be encrypted by Staticrypt and all users will need to enter a password to decrypt and view.
Demo site
Demo: Spacebook (Password = spacebook)
Did you know? Netlify does not allow for basic authentication on their free tier. If you are already on a paid plan or are willing to do so, then it is better to simply set up basic authentication via your dashboard instead of using the instructions below.
Set a password in Netlify
Visit your Netlify dashboard and go to Site settings > Build & deploy > Environment
Click Edit variables and a new variable with the key PASSWORD with the value set to the password of your choice for unlocking your site:
If you ever change this password, all of your users will be prevented from accessing your content until they have the new password.
Enable encryption
In your _data/site.json file, set encryption to true:
{
...
"enableEncryption": true π set this to true!
...
}
This will enable a logout button that appears in your header whenever encryption is enabled.
Change your build command
Now you need to change the build command in your netlify.toml file. Comment out the current npm run build command and enable the command directly below it like so:
[build]
publish = "_site"
comment this line π #command = "npm run build"
uncomment this one π command = "npm run build && set -e && find ./_site -type f -name '*.html' -exec staticrypt -f password_template.html {} $PASSWORD -o {} \\;"
Thatβs it! π
When you deploy your site all of your pages will be encrypted at build time and require a password to access. The passphrase is stored in local storage and users remain logged in for future visits until they click the logout button (), or an administrator changes the password.
If you ever want to remove password protection, simply reverse this process and your site will no longer be encrypted at build time.
Did you know? Because all of your pages are being decrypted on the fly at the time of access, there is a small delay between page loads so you will see a small loading spinner that you wonβt otherwise see on a spacebook site. π