spatie/laravel-littlegatekeeper
Laravel middleware to password-protect your app with a single, universal username/password set in config. Quickly gate staging, previews, or temporary launches without building a full auth system; publish config and enable the provider to lock down pages.
Installation:
composer require spatie/laravel-littlegatekeeper
Publish the config file:
php artisan vendor:publish --provider="Spatie\Littlegatekeeper\LittlegatekeeperServiceProvider"
Configure:
Edit .env or config/littlegatekeeper.php:
LITTLEGATEKEEPER_USERNAME=admin
LITTLEGATEKEEPER_PASSWORD=securepassword
First Use Case: Protect a route or controller method:
use Spatie\Littlegatekeeper\Middleware\CheckLittlegatekeeper;
Route::get('/admin', function () {
return 'Admin Dashboard';
})->middleware(CheckLittlegatekeeper::class);
Route Protection: Apply middleware to routes, controllers, or groups:
Route::middleware([CheckLittlegatekeeper::class])->group(function () {
Route::get('/secret', 'SecretController@index');
});
Dynamic Credentials: Override credentials per request (e.g., API keys):
Littlegatekeeper::setCredentials('api_user', 'api_key');
Custom Views:
Extend the default 403 view by publishing assets:
php artisan vendor:publish --tag=littlegatekeeper-views
Then customize resources/views/vendor/littlegatekeeper/403.blade.php.
Route::middleware([CheckLittlegatekeeper::class, 'auth:sanctum'])->get('/api/admin');
'enabled' => env('APP_ENV') !== 'production',
Middleware Order:
Place CheckLittlegatekeeper before other auth middleware (e.g., auth) to avoid bypassing it.
Password Hashing:
The package does not hash passwords by default. Store plaintext credentials securely (e.g., .env or secrets manager).
Caching: Credentials are not cached. Repeated failed attempts may log multiple entries.
Littlegatekeeper errors.app/Http/Kernel.php under $routeMiddleware.Custom Logic:
Override the CheckCredentials contract to add logic (e.g., IP whitelisting):
Littlegatekeeper::setCredentialsChecker(function ($username, $password) {
return $username === 'admin' && $password === 'secure' && request()->ip() === '192.168.1.1';
});
Rate Limiting:
Combine with Laravel’s throttle middleware to limit login attempts:
Route::middleware([CheckLittlegatekeeper::class, 'throttle:5,1'])->get('/login');
Multi-Tenant:
Use the setCredentials method dynamically per tenant:
Littlegatekeeper::setCredentials(Tenant::current()->admin_username, Tenant::current()->admin_password);
How can I help you explore Laravel packages today?