In this recipe, we will build a login user interface for authenticating with our back-end and create an Observable for monitoring the user authentication:
- First, we will need to update our /src/app/current-user.service.ts service to connect to our back-end API. We will do this by adding two new methods for login and logout . We will send an HTTP Post request to our API's /api/login route using Angular's HTTP module. We will also change our relationship with our user object to be managed through an Observable provided by our getUser method. This will allow different parts of our app to listen to data-binding changes on our user object in real time:
import { Injectable } from '@angular/core';import {User} from "./user";import ...