title: Angular HttpErrorResponse 401 (Unauthorized)
body: <p>I'm making an web app on Angular and Loopback but when trying to login from frontend, it throws the following error:</p>
  
  <p><code>POST http://localhost:3000/api/usuarios/login?include=User 401 (Unauthorized)</code></p>
  
  <p><code>ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "Unauthorized", url: "http://localhost:3000/api/usuarios/login?include=User", ok: false, …}</code></p>
  
  <p>Bellow a detailed error code:</p>
  
  <pre><code>status: 401
  statusText: "Unauthorized"
  url: "http://localhost:3000/api/usuarios/login?include=User"
  ok: false
  name: "HttpErrorResponse"
  message: "Http failure response for http://localhost:3000/api/usuarios/login?include=User: 401 Unauthorized"
  error: {error: {…}}
  __proto__: HttpResponseBase 
  </code></pre>
  
  <p>I think I have no mistaken code neither on security model nor on login-component.ts, but I would anyway prefer this code to be reviewed.</p>
  
  <p><strong>security.service.ts</strong></p>
  
  <pre><code>import { BehaviorSubject, Observable } from 'rxjs';
  import { UsuarioModel } from '../models/usuario.model';
  import { HttpClient, HttpHeaders } from '@angular/common/http';
  
  
  @Injectable({
    providedIn: 'root'
  })
  export class SecurityService {
  
    name:string='';
  
  
    userLogged:boolean=false;
  
    url:String= "http://localhost:3000/api/usuarios/";
    infoUsuario= new BehaviorSubject&lt;UsuarioModel&gt;(new UsuarioModel());
  
    constructor(private http: HttpClient) { 
      this.verificarSesionUsuario();
    }
  
    loginUser(username:String,pass:String):Observable&lt;UsuarioModel&gt;
    {
         return this.http.post&lt;UsuarioModel&gt;(`${this.url}login?include=User`, {
         email:username,
         contraseña:pass
       },
       {
         headers: new HttpHeaders({
           "content-type":"application/json"
         })
       })
  }
  
  } 
  
  </code></pre>
  
  <p><strong>login.component.ts</strong></p>
  
  <pre><code>import {FormGroup, FormBuilder,Validators} from '@angular/forms';
  import{Router}from'@angular/router';
  import{SecurityService}from'src/app/services/security.service';
  
  
  declare var openPlatformModalMessage: any
  
  @Component({
    selector: 'app-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.css']
  
  })
  export class LoginComponent implements OnInit {
  
    fgValidation:FormGroup;
  
    constructor(private fb:FormBuilder, private secService:SecurityService,
  
      private router:Router) { }
  
    ngOnInit() {
      this.fgValidationBuilder();
    }
  
    loginEvent(){
      if(this.fgValidation.invalid){
        alert("Datos erróneos");
  
      }
      else{
        let u =this.fg.username.value;
        let p=this.fg.password.value;
  
        this.secService.loginUser(u,p).subscribe(data=&gt;{
  
          if (data != null){
            console.log(data)
            this.router.navigate(['/home']);
            this.secService.saveLoginInfo(data);
        }
  
        else
        {
          openPlatformModalMessage("Los datos no son válidos!");
        }
      });
     }
    }
  }
  </code></pre>
  
  <p>I've verified the URL request on Postman and it didn't throw any error.
  I watched other similar posts but I saw that 401 error can have different origins</p>
  
  <p>How can I solve this error?</p>