0

I have an API, using the ASP core as my back end. At the back end, a JWT is generated. I can access the data from the postman using the generated token. But using Angular, I do not understand how to access that token. My question is, how to give the token to Angular and how to access Authorized Endpoints?

Here is my HTML form

            <form>
                <label for="">Username</label>
                <input type="text" name="username" id="username" class="form-control mb-2" [(ngModel)]="usrname">

                <label for="">Password</label>
                <input type="password" name="password" id="password" class="form-control" [(ngModel)]="password">

                <button class="btn btn-primary mt-3" (click)="submit()">Submit</button>
            </form>

Here is the code in my TS file

submit(){
var submitdata = {
  username:this.usrname,
  Password:this.password
}
this.service.loginProcess(submitdata).subscribe(results =>{
  console.log(results);
});

}

This is the service file

loginProcess(data:any){
return this.http.post(this.ProServiceAPIUrl + '/Logins',data);

}

  • 2
    Register a http interceptor, intercept every request and add required headers, if you search on the web is full of examples – Sergio Rinaudo Jun 16 '22 at 14:24
  • The interceptor syntax is still valid in ng14 https://stackoverflow.com/questions/45418477/angular-4-3-interceptor-not-working – Sergio Rinaudo Jun 16 '22 at 14:26

0 Answers0