BookMonkey 4 Diff

Files changed (4) hide show
  1. tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/app.module.ts +5 -2
  2. tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/search/search.component.html +0 -1
  3. tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/shared/book-store.service.ts +1 -1
  4. tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/shared/token.interceptor.ts +25 -0
tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/app.module.ts RENAMED
@@ -1,6 +1,6 @@
1
  import { CommonModule } from '@angular/common';
2
  import { NgModule } from '@angular/core';
3
- import { HttpClientModule } from '@angular/common/http';
4
   
5
  import { AppRoutingModule } from './app-routing.module.one-app';
6
  import { AppComponent } from './app.component';
@@ -9,6 +9,7 @@
9
  import { BookListItemComponent } from './book-list-item/book-list-item.component';
10
  import { BookDetailsComponent } from './book-details/book-details.component';
11
  import { SearchComponent } from './search/search.component';
   
12
   
13
  @NgModule({
14
  declarations: [
@@ -24,7 +25,9 @@
24
  HttpClientModule,
25
  AppRoutingModule
26
  ],
27
- providers: [],
   
   
28
  bootstrap: [AppComponent]
29
  })
30
  export class AppModule { }
1
  import { CommonModule } from '@angular/common';
2
  import { NgModule } from '@angular/core';
3
+ import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
4
   
5
  import { AppRoutingModule } from './app-routing.module.one-app';
6
  import { AppComponent } from './app.component';
9
  import { BookListItemComponent } from './book-list-item/book-list-item.component';
10
  import { BookDetailsComponent } from './book-details/book-details.component';
11
  import { SearchComponent } from './search/search.component';
12
+ import { TokenInterceptor } from './shared/token.interceptor';
13
   
14
  @NgModule({
15
  declarations: [
25
  HttpClientModule,
26
  AppRoutingModule
27
  ],
28
+ providers: [
29
+ { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }
30
+ ],
31
  bootstrap: [AppComponent]
32
  })
33
  export class AppModule { }
tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/search/search.component.html RENAMED
@@ -1,6 +1,5 @@
1
  <div class="ui search" [class.loading]="isLoading">
2
  <div class="ui icon input">
3
-
4
  <input type="text" class="prompt" #input
5
  (keyup)="keyUp$.next(input.value)">
6
  <i class="search icon"></i>
1
  <div class="ui search" [class.loading]="isLoading">
2
  <div class="ui icon input">
   
3
  <input type="text" class="prompt" #input
4
  (keyup)="keyUp$.next(input.value)">
5
  <i class="search icon"></i>
tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/shared/book-store.service.ts RENAMED
@@ -11,7 +11,7 @@
11
  providedIn: 'root'
12
  })
13
  export class BookStoreService {
14
- private api = 'https://api4.angular-buch.com';
15
   
16
  constructor(private http: HttpClient) {}
17
   
11
  providedIn: 'root'
12
  })
13
  export class BookStoreService {
14
+ private api = 'https://api4.angular-buch.com/secure';
15
   
16
  constructor(private http: HttpClient) {}
17
   
tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/shared/token.interceptor.ts RENAMED
@@ -0,0 +1,25 @@
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
1
+ import { Injectable } from '@angular/core';
2
+ import {
3
+ HttpRequest,
4
+ HttpHandler,
5
+ HttpEvent,
6
+ HttpInterceptor
7
+ } from '@angular/common/http';
8
+ import { Observable } from 'rxjs';
9
+  
10
+ @Injectable()
11
+ export class TokenInterceptor implements HttpInterceptor {
12
+ private authToken = '1234567890';
13
+  
14
+ intercept(
15
+ request: HttpRequest<unknown>,
16
+ next: HttpHandler
17
+ ): Observable<HttpEvent<unknown>> {
18
+ const newRequest = request.clone({
19
+ setHeaders: {
20
+ Authorization: `Bearer ${this.authToken}`
21
+ }
22
+ });
23
+ return next.handle(newRequest);
24
+ }
25
+ }