jorisnoo / statamic-password-protect
Site-wide password protection for anonymous visitors
Package info
github.com/jorisnoo/statamic-password-protect
Type:statamic-addon
pkg:composer/jorisnoo/statamic-password-protect
Requires
- php: ^8.3
- statamic/cms: ^6.0
Requires (Dev)
- orchestra/testbench: ^10.0
- pestphp/pest: ^3.0
README
Site-wide password protection for Statamic 6. Anonymous visitors must enter a password to view the site. Logged-in CP users always bypass the wall.
Settings are managed through the addon settings page in the Statamic control panel.
Requirements
- PHP 8.3+
- Statamic 6
- Laravel 12
Installation
composer require jorisnoo/statamic-password-protect
Configuration
- Go to CP > Addons > Password Protect > Settings
- Toggle Enabled on
- Set a Password
- Optionally set a Title for the password page (defaults to your site name)
- Save
That's it. Anonymous visitors will now see a password prompt. Authenticated CP users are never affected.
How It Works
A middleware on the web group intercepts every frontend request. It checks (in order):
- Is password protection enabled with a password set? If not, pass through.
- Is this a CP route? Pass through.
- Is this the password form itself? Pass through.
- Is the visitor logged into Statamic? Pass through.
- Does the session have a valid authorization flag? Pass through.
- Otherwise, redirect to the password form.
After entering the correct password, visitors are redirected back to the page they originally requested. The session flag persists for the duration of the browser session.
Static Caching
When password protection is enabled, the addon automatically disables Statamic's static caching strategy. This ensures every request goes through the middleware and anonymous visitors cannot access cached pages.
When you disable password protection, static caching resumes normally.
SSG (Static Site Generator): This addon is not compatible with statamic/ssg. If you're generating a fully static site, password protection must be handled at the web server level (e.g., HTTP Basic Auth via nginx/Apache).
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.