From 7961217a91f522a64f079e11d1048556f095c561 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Wed, 26 Nov 2025 13:29:40 +0100 Subject: [PATCH] Add `isAuthenticated` method to `route_t` for user authentication check --- services/nginx/app/traits/route_t.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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