mirror of
https://gh.wpcy.net/https://github.com/fairpm/aspirecloud.git
synced 2026-06-20 02:22:28 +08:00
* feat: make api token optional for user api routes * config: disable deprecations in production php.ini files dev should probably override this setting, but keeping it as-is for now
22 lines
578 B
PHP
22 lines
578 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
|
|
|
class AuthOptional
|
|
{
|
|
public function handle(Request $request, Closure $next, string $gate): Response
|
|
{
|
|
if ($request->bearerToken()) {
|
|
$user = auth($gate)->user() or throw new UnauthorizedHttpException('Invalid authentication token');
|
|
auth($gate)->setUser($user);
|
|
}
|
|
return $next($request);
|
|
}
|
|
}
|