shiftechafrica/laravel-multiple-guards
Auth facade and Guard contracts, ensuring seamless integration with existing auth logic (e.g., middleware, policies, providers).config/auth.php, allowing granular control over guard-specific rules (e.g., rate limiting, session handling).auth:api) must be extended to support guard-specific logic (e.g., auth:guard=admin).AuthServiceProvider.composer.json for exact versions). Verify compatibility with your stack (e.g., PHP 8.1+).Phase 1: Configuration
config/auth.php to define multiple guards:
'guards' => [
'web' => ['driver' => 'session', 'provider' => 'users'],
'api' => ['driver' => 'token', 'provider' => 'users'],
'admin' => ['driver' => 'session', 'provider' => 'admins'],
],
admins table).Phase 2: Middleware
auth middleware with guard-aware versions:
Route::middleware(['auth:guard=admin'])->group(...);
Phase 3: Logic Adaptation
Auth::user()) to handle guard contexts:
$user = Auth::guard('admin')->user();
Phase 4: Testing
admins) must exist.config/auth.php.Auth::shouldUse('admin')) to reduce overhead.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Guard session collision | User data corruption | Isolate sessions (e.g., session.driver=redis per guard). |
| Token leakage between guards | Security breach | Use guard-specific token prefixes. |
| Middleware misconfiguration | Auth bypass | Unit test all guard-aware middleware. |
| Database provider errors | Guard unavailability | Implement fallback guards or retries. |
| PHP/Laravel version incompatibility | Deployment blocker | Pin versions in composer.json. |
admin guard failure").Auth::guard()->getLastAttempted()) to observability tools.How can I help you explore Laravel packages today?