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
|
|
|
|
{
|
2022-07-29 06:47:10 +00:00
|
|
|
public function __construct(protected Guard $auth)
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if ($this->auth->guest()) {
|
2022-07-28 05:48:04 +00:00
|
|
|
if ($request->ajax() || $request->wantsJson() || $request->route()->getName() === 'play') {
|
2015-12-13 04:42:28 +00:00
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
2020-09-06 18:21:39 +00:00
|
|
|
return redirect()->guest('/');
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|