Commit 94505250 authored by Joseph Silber's avatar Joseph Silber

Use the Authenticate middleware from core

parent 3ddaf3f9
...@@ -46,7 +46,7 @@ class Kernel extends HttpKernel ...@@ -46,7 +46,7 @@ class Kernel extends HttpKernel
* @var array * @var array
*/ */
protected $routeMiddleware = [ protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class, 'auth' => \Illuminate\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class, 'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
......
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\AuthenticationException;
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function authenticate(array $guards)
{
if (count($guards) <= 1) {
Auth::guard(array_first($guards))->authenticate();
return Auth::shouldUse($guard);
}
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return Auth::shouldUse($guard);
}
}
throw new AuthenticationException;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment