j84115/impersonate
Simple Laravel package to temporarily impersonate other users via /impersonate/login/{user_id} and /impersonate/logout. Add service provider, implement ImpersonateUser on your User model to define who can impersonate and who can be impersonated, then register Route::impersonate().
ImpersonateUser interface enforces a clean contract, allowing flexibility in defining impersonation rules (e.g., impersonator(), impersonatable()) without hardcoding logic.Route::impersonate() macro suggests it hooks into Laravel’s middleware pipeline, but the actual implementation (e.g., session hijacking, auth guard switching) isn’t fully transparent. Risk: Potential conflicts with custom auth logic or session drivers (e.g., Redis, database).User model to implement ImpersonateUser, which may not align with projects using abstracted auth (e.g., Fortify, Sanctum) or third-party user models.web). Risk: Projects using multi-guard setups (e.g., API + web) could face integration gaps.web, api) in use? If so, how will impersonation scope to the correct guard?file, redis, database)? Are there known issues with the package’s session manipulation?User model extensible (e.g., via traits) or tightly coupled to the app? Modifying it for this interface may require refactoring.Auth::login(), session-based auth). Fit: Excellent for monolithic Laravel apps using traditional session auth.User model. Fit: Works with Eloquent, but may need adaption for non-Eloquent user models.AuthServiceProvider, User model, or middleware that could conflict.config/session.php).ImpersonateServiceProvider in config/app.php.User model with ImpersonateUser and implement impersonator()/impersonatable().Route::impersonate() to routes/web.php (guard with auth middleware).auth, throttle). Mitigation: Test with a dedicated test route first.impersonator() logic) and test with varied user roles.impersonator()) will need updates if role/permission systems evolve.Route::impersonate() should not be cached).ImpersonateServiceProvider.impersonator() logic or middleware bypass.CanImpersonate gate).currently_impersonating flag to the User model.ImpersonateServiceProvider to test session binding.How can I help you explore Laravel packages today?