Melhorias método autenticated
protected User authenticated() {
try {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Jwt jwtPrincipal = (Jwt) authentication.getPrincipal();
String username = jwtPrincipal.getClaim("username");
return repository.findByEmail(username).get();
}
catch (Exception e) {
throw new UsernameNotFoundException("Invalid user");
}
}
Faremos o seguinte: o primeiro bloco do Try, tudo que está dentro dele, iremos alocar para uma nova classe chamada "CustomUserUtil" no pacote Util (essa classe será um @Component).

Incluindo no UserService
Importa o component criado

E coloca no bloco do Try

Atualizado