Fix: search by email on register

This commit is contained in:
Jose
2026-02-16 01:13:10 +01:00
parent 3796e6f190
commit 7c70af6a8c
3 changed files with 8 additions and 6 deletions

View File

@@ -38,7 +38,8 @@ public interface CredentialRepository extends JpaRepository<Credential, byte[]>
@Query("SELECT c FROM Credential c WHERE c.userIdBin = :userIdBin")
List<Credential> findByUserId(@Param("userIdBin") byte[] userIdBin);
List<Credential> findByEmail(String email);
@Query("SELECT c FROM Credential c WHERE c.email = :email")
List<Credential> findByEmail(@Param("email") String email);
boolean existsByUsernameAndServiceId(String username, Byte serviceId);

View File

@@ -1,5 +1,6 @@
package net.miarma.backend.core.service;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -57,9 +58,10 @@ public class AuthService {
userIdByUsername = credByUsername.get().getUserId();
}
try {
userIdByEmail = credentialService.getByEmail(request.email()).get(0).getUserId();
} catch (NotFoundException e) { }
List<Credential> accountsByEmail = credentialService.getByEmail(request.email());
if (!accountsByEmail.isEmpty()) {
userIdByEmail = accountsByEmail.getFirst().getUserId();
}
User user;
if (userIdByUsername != null && userIdByEmail != null) {

View File

@@ -88,8 +88,7 @@ public class CredentialService {
}
public List<Credential> getByEmail(String email) {
return credentialRepository.findByEmail(email).stream()
.toList();
return credentialRepository.findByEmail(email);
}
public Credential getByUserIdAndService(UUID userId, Byte serviceId) {