An interceptor adds the token in Angular

Angular interview exercise on HttpClient, difficulty 3 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.

TokenService holds a `token` signal ("" when signed out). Write authInterceptor: when a token is set, it adds the header Authorization: Bearer <token> to every request; without one the request goes out untouched. Export `appConfig` providing HttpClient with the interceptor. ProfileComponent loads GET /api/me ({ name }) into a `me` signal and shows the name in <p class="name">.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.

More HttpClient in Angular

All Angular exercises · Other languages and frameworks