authService = $authService; } /** * Check if user is authenticated (API endpoint) */ public function checkAuth(Request $request, Response $response, $args) { try { if (!$this->authService->isLoggedIn()) { return $this->jsonResponse($response->withStatus(401), [ 'error' => '401 Forbidden' ]); } $user = $this->authService->getCurrentUser(); if (!$user) { return $this->jsonResponse($response->withStatus(401), [ 'error' => '401 Forbidden' ]); } return $this->jsonResponse($response, [ 'id' => $user['id'], 'username' => $user['username'], 'email' => $user['email'], 'is_admin' => $this->authService->isAdmin() ]); } catch (\Exception $e) { return $this->jsonResponse($response->withStatus(500), [ 'error' => 'Authentication check failed' ]); } } }