2026-05-16 09:21:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Blax\Workkit\Middleware;
|
|
|
|
|
|
2026-05-17 12:39:14 +00:00
|
|
|
use Blax\Workkit\Services\ResponseService;
|
2026-05-16 09:21:32 +00:00
|
|
|
use Closure;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
|
|
class RequireAuthMiddleware
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Handle an incoming request.
|
|
|
|
|
*
|
|
|
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
|
|
|
*/
|
|
|
|
|
public function handle(Request $request, Closure $next, string $action = 'continue'): Response
|
|
|
|
|
{
|
|
|
|
|
if (! Auth::check()) {
|
2026-05-17 12:39:14 +00:00
|
|
|
return ResponseService::apiError(
|
|
|
|
|
"You need to be logged in to {$action}.",
|
2026-05-16 09:21:32 +00:00
|
|
|
Response::HTTP_UNAUTHORIZED,
|
2026-05-17 12:39:14 +00:00
|
|
|
type: 'AuthenticationException',
|
2026-05-16 09:21:32 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
|
}
|
|
|
|
|
}
|