feat(auth): POST /auth/login retourne email, name, role et token
- Champ `name` ajouté sur User, UserEntity, RegisterRequest - AuthenticateUserUseCase retourne Result(user, token) au lieu du token seul - UserNotFoundException remplacé par BadCredentialsException au login (pas de fuite d'info) - @Email retiré de LoginRequest (identifiant = "gato", pas nécessairement un email) - Migration V2 : colonne name + utilisateur par défaut gato/change (ADMIN) - bytecode cible Java 21 (ASM Spring Boot 3.4 ne supporte pas Java 25) - Tests : AbstractIntegrationTest simplifié, URL TC JDBC + network host Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package com.olhar.olharapi.application.usecase;
|
||||
|
||||
import com.olhar.olharapi.application.port.in.AuthenticateUserUseCase;
|
||||
import com.olhar.olharapi.application.port.out.UserRepository;
|
||||
import com.olhar.olharapi.domain.exception.UserNotFoundException;
|
||||
import com.olhar.olharapi.domain.model.User;
|
||||
import com.olhar.olharapi.infrastructure.security.JwtService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -19,14 +18,14 @@ public class AuthenticateUserService implements AuthenticateUserUseCase {
|
||||
private final JwtService jwtService;
|
||||
|
||||
@Override
|
||||
public String authenticate(Command command) {
|
||||
public Result authenticate(Command command) {
|
||||
User user = userRepository.findByEmail(command.email())
|
||||
.orElseThrow(() -> new UserNotFoundException(command.email()));
|
||||
.orElseThrow(() -> new BadCredentialsException("Identifiants invalides"));
|
||||
|
||||
if (!passwordEncoder.matches(command.password(), user.passwordHash())) {
|
||||
throw new BadCredentialsException("Invalid credentials");
|
||||
throw new BadCredentialsException("Identifiants invalides");
|
||||
}
|
||||
|
||||
return jwtService.generateToken(user);
|
||||
return new Result(user, jwtService.generateToken(user));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user