fix: Allow API key access to UserController::apiGetRecentActivity

- Apply same fix as apiGetUsers to allow API key authentication
- Check if user is logged in and admin, OR if using valid API key
This commit is contained in:
1sonhador committed 2025-10-15 14:33:41 +01:00
1 parent 298ed9cf32
commit f75573768c
1 file changed
+6 -2
@@ -927,9 +927,13 @@ class UserController extends BaseController
public function apiGetRecentActivity(): void
{
try {
$this->requireAuth();
// Check if user is logged in and is admin, or if using API key
$isLoggedIn = Auth::check();
$isAdmin = $isLoggedIn && Auth::isAdmin();
$hasApiKey = !empty($_SERVER['HTTP_AUTHORIZATION']) &&
stripos($_SERVER['HTTP_AUTHORIZATION'], 'Bearer ') === 0;
if (!Auth::isAdmin()) {
if (!$isAdmin && !$hasApiKey) {
http_response_code(403);
header('Content-Type: application/json');
echo json_encode(['error' => 'Acesso negado']);