Skip to content

Two access to the database in the login method #4

@gussttaav

Description

@gussttaav

The following section of code accesses the database twice: once to retrieve the UserDetails required by Spring Security, and again to obtain all user data to return in the request. Also, the ResourceNotFoundException is never thrown if the user's email does not exist; the UsernameNotFoundException exception is thrown first when usuarioDetallesService.loadUserByUsername is called.

UserDetails userDetails = usuarioDetallesService.loadUserByUsername(loginDTO.email());

Usuario usuario = usuarioRepository.findByEmail(loginDTO.email())
    .orElseThrow(() -> new ResourceNotFoundException(
        "No existe ningún usuario con el email proporcionado"
    ));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions