diff --git a/simple-jwt-login/src/Services/AuthenticateService.php b/simple-jwt-login/src/Services/AuthenticateService.php index b059485..4fdac8b 100644 --- a/simple-jwt-login/src/Services/AuthenticateService.php +++ b/simple-jwt-login/src/Services/AuthenticateService.php @@ -98,7 +98,12 @@ public function authenticateUser() ErrorCodes::AUTHENTICATION_MISSING_PASSWORD ); } - + + if (isset($this->request['username']) && str_contains($this->request['username'], '@')) { + $this->request['email'] = $this->request['username']; + unset($this->request['username']); + } + $user = isset($this->request['username']) ? $this->wordPressData->getUserByUserLogin( $this->wordPressData->sanitizeTextField($this->request['username']) diff --git a/tests/Services/AuthenticateServiceTest.php b/tests/Services/AuthenticateServiceTest.php index 105a593..2b5fccc 100644 --- a/tests/Services/AuthenticateServiceTest.php +++ b/tests/Services/AuthenticateServiceTest.php @@ -270,6 +270,9 @@ public function testSuccessFlowWithFullPayload() $this->wordPressDataMock ->method('getUserByUserLogin') ->willReturn('user'); + $this->wordPressDataMock + ->method('getUserDetailsByEmail') + ->willReturn('user'); $this->wordPressDataMock ->method('getUserPassword') ->willReturn('1234'); @@ -323,6 +326,9 @@ public function testSuccessFlowWithFullPayloadAndPasshash() $this->wordPressDataMock ->method('getUserByUserLogin') ->willReturn('user'); + $this->wordPressDataMock + ->method('getUserDetailsByEmail') + ->willReturn('user'); $this->wordPressDataMock ->method('getUserPassword') ->willReturn('1234');