diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index e934a2799c..f9b2753eb6 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -876,12 +876,6 @@ App::patch('/v1/projects/:projectId/auth/mock-numbers') ->inject('dbForConsole') ->action(function (string $projectId, array $numbers, Response $response, Database $dbForConsole) { - $project = $dbForConsole->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - $uniqueNumbers = []; foreach ($numbers as $number) { if (isset($uniqueNumbers[$number['phone']])) { @@ -889,6 +883,12 @@ App::patch('/v1/projects/:projectId/auth/mock-numbers') } $uniqueNumbers[$number['phone']] = $number['otp']; } + + $project = $dbForConsole->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } $auths = $project->getAttribute('auths', []); diff --git a/src/Appwrite/Auth/Validator/MockNumber.php b/src/Appwrite/Auth/Validator/MockNumber.php index 6f1cf81cae..ac5ba89fc5 100644 --- a/src/Appwrite/Auth/Validator/MockNumber.php +++ b/src/Appwrite/Auth/Validator/MockNumber.php @@ -46,8 +46,8 @@ class MockNumber extends Validator return false; } - $otp = new Text(6, 6); - if (!$otp->isValid($value['otp']) || !\ctype_digit($value['otp'])) { + $otp = new Text(6, 6, Text::NUMBERS); + if (!$otp->isValid($value['otp'])) { $this->message = 'Invalid OTP. Please make sure the OTP is a 6 digit number'; return false; }