diff --git a/services/nginx/app/traits/route_t.php b/services/nginx/app/traits/route_t.php index 5d5c68c9..2a897397 100644 --- a/services/nginx/app/traits/route_t.php +++ b/services/nginx/app/traits/route_t.php @@ -23,6 +23,26 @@ trait route_t // Add the routes here } + /** + * Is authenticated? + * This function returns a boolean indicating if the user is authenticated + * @return bool + */ + public function isAuthenticated(): bool + { + global $response; + try { + $user = (new authentication())->get_user(); + // If there is no user, return false + if (!$user) { + return false; + } + return true; + } catch (Exception $e) { + $response->error($e->getMessage(), 400); + } + } + /** * Require type * @param mixed $value