Attaching the token to the request with an interceptor
So far, our backend doesn’t have any kind of authentication control, which doesn’t happen (or at least it shouldn’t happen) in the real world. The backend was modified to perform authentication, but this was reflected in the frontend because, if we tried to log in, the following error would occur:
ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":401,"statusText":"Unauthorized","url":"http://localhost:3000/diary","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://localhost:3000/diary: 401 Unauthorized","error":{"message":"Unauthorized","statusCode":401}}
This error means that our request was rejected by the server because it was not authorized...