Pagination on the list, optional auth
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Khofmann\Auth;
|
||||
|
||||
use Exception;
|
||||
use Pecee\Http\Middleware\IMiddleware;
|
||||
use Pecee\Http\Request;
|
||||
use Khofmann\Models\User\User;
|
||||
use Khofmann\Response\Response;
|
||||
|
||||
class OptAuth implements IMiddleware
|
||||
{
|
||||
public function handle(Request $request): void
|
||||
{
|
||||
$token = $request->getHeader("token");
|
||||
|
||||
// No token
|
||||
if ($token === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
User::getByToken($token);
|
||||
} catch (Exception $err) {
|
||||
// No user with this token exists
|
||||
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user