Skip to content

Instantly share code, notes, and snippets.

@duncanmcclean
Created March 3, 2022 00:11
Show Gist options
  • Save duncanmcclean/618f45c990fcfb1620da1a7f0647f784 to your computer and use it in GitHub Desktop.
Save duncanmcclean/618f45c990fcfb1620da1a7f0647f784 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Statamic\Facades\User;
class AutomaticallyLogin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (Auth::guest()) {
$user = User::findByEmail('[email protected]');
Auth::login($user);
}
return $next($request);
}
}
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// ...
\App\Http\Middleware\AutomaticallyLogin::class,
];
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment