How to get my token and user from the backend to the front-end

36 views Asked by At

Error Image

This is my userservice.ts file code

export class UserService {

  BASE_URL = "http://localhost:8082";
  constructor(private httpClient:HttpClient) {}

  public login(loginData:any){
    return this.httpClient.post(this.BASE_URL+"/authenticate",loginData);
  
  } 
}

this is my login.component.ts file

export class LoginComponent implements OnInit {

  constructor(private userService:UserService){}

  ngOnInit(): void {}

  login(loginFormData:NgForm){
    this.userService.login(loginFormData.value).subscribe(
      (response) =>{
        console.log(response);
      },
      (error=>{
        console.log(error);
      })
    );
  }

}
1

There are 1 answers

1
Mohameden Haden On

Based on the server response you can acces your token and using interceptors you can append the token to any future requests if verification is needed.