koel/app/Http/Middleware/Authenticate.php

22 lines
449 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
2018-08-24 15:27:19 +00:00
use Illuminate\Http\Request;
2022-11-16 17:57:38 +00:00
use Illuminate\Http\Response;
2015-12-13 04:42:28 +00:00
class Authenticate
{
2021-06-05 10:47:56 +00:00
public function handle(Request $request, Closure $next) // @phpcs:ignore
2015-12-13 04:42:28 +00:00
{
2022-11-16 17:57:38 +00:00
if ($request->user()?->tokenCan('*')) {
return $next($request);
}
abort_if($request->ajax() || $request->wantsJson(), Response::HTTP_UNAUTHORIZED);
2015-12-13 04:42:28 +00:00
2022-11-16 17:57:38 +00:00
return redirect()->guest('/');
2015-12-13 04:42:28 +00:00
}
}