koel/app/Http/Middleware/Authenticate.php

31 lines
622 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
2018-08-24 15:27:19 +00:00
use Illuminate\Http\Request;
2015-12-13 04:42:28 +00:00
class Authenticate
{
protected $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
2018-08-24 15:27:19 +00:00
public function handle(Request $request, Closure $next)
2015-12-13 04:42:28 +00:00
{
if ($this->auth->guest()) {
2016-08-03 10:42:11 +00:00
if ($request->ajax() || $request->route()->getName() === 'play') {
2015-12-13 04:42:28 +00:00
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
return $next($request);
}
}