Auth Interceptor
Understand how to create an Auth Interceptor service in Angular that adds JWT authorization headers to HTTP requests. Learn to modify and handle outgoing requests securely by retrieving tokens from localStorage, ensuring authenticated interactions with the API during event creation.
We'll cover the following...
The Create Event section within the API documentation shows the endpoint our application should aim for, along with the example request body and response. In addition to those is a section labeled “Example header.” This header contains an Authorization property with a value containing a JWT.
To create events, we’ll need to pass the JWT from localStorage with our request so that the API knows the request is coming from an authenticated user.
To do this, we’ll leverage a feature within Angular known as an HttpInterceptor. An HttpInterceptor allows us to intercept HTTP requests, modifying them to our liking before they are sent.
We’ll use an interceptor to modify ...