From 7929a1875a2717737113785ca9188c63600049be Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Thu, 19 Dec 2024 12:44:45 +0100 Subject: [PATCH] Fixed a bug when no authorization token was provided. --- routes/authRoute.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/routes/authRoute.php b/routes/authRoute.php index c521f52b..19861af5 100644 --- a/routes/authRoute.php +++ b/routes/authRoute.php @@ -3,10 +3,8 @@ namespace routes; use classes\authentication; -use classes\encrypt; use objects\logs_o; use objects\tokens_o; -use objects\users_o; use traits\route_t; class authRoute @@ -20,8 +18,12 @@ class authRoute global $response; $data = json_decode(file_get_contents('php://input'), true); // Check if the customer number, and password are set - if (!isset($data['customer_number'])) { $response->error('Customer number is required', 400); } - if (!isset($data['password'])) { $response->error('Password is required', 400); } + if (!isset($data['customer_number'])) { + $response->error('Customer number is required', 400); + } + if (!isset($data['password'])) { + $response->error('Password is required', 400); + } // Try to log the user in $isCredentialsValid = (new authentication())->authenticate($data['customer_number'], $data['password']); // Log the incident @@ -40,7 +42,7 @@ class authRoute $this->get('/auth/logout', function () { // Get the token from the headers global $response; - $token = $_SERVER['HTTP_AUTHORIZATION']; + $token = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; // Remove the Bearer prefix $token = str_replace('Bearer ', '', $token); // Check if the token is valid @@ -56,7 +58,7 @@ class authRoute $this->get('/auth/session', function () { // Get the token from the headers global $response; - $token = $_SERVER['HTTP_AUTHORIZATION']; + $token = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; // Default to empty string if not set // Remove the Bearer prefix $token = str_replace('Bearer ', '', $token); // Check if the token is valid