How to do it...

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:

  1. 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 ...

Get MEAN Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.