How to use authorization headers
When we talk about authorization in the header, we are basically talking about making some modifications in the header of the application to send some kind of authorization. In our case, we are specifically talking about an authorization token generated by our API backend.
The best way to do this is by using Angular interceptors. An interceptor, as its name suggests, allows us to simply intercept and configure requests before they are triggered to the server.
This allows us to do a lot of things. An example of this would be to configure a token authentication on any request, or suddenly add custom headers that our application may need, until we handle answers before finishing the request.
When a JWT token is sent to the backend, remember that we are using the jwt-auth
library on our Laravel API: it is expected to be in the authorization header of the HTTP request.
The most common approach for adding an authorization header to an HTTP request in Angular is creating...