BookMonkey 3 Diff

Files changed (3) 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}/shared/book-store.service.ts +1 -1
  3. tmp/src/app/book-monkey/iteration-3/{rxjs → interceptors}/shared/token-interceptor.ts +20 -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}/shared/book-store.service.ts RENAMED
@@ -11,7 +11,7 @@
11
providedIn: 'root'
12
})
13
export class BookStoreService {
14
- private api = 'https://api3.angular-buch.com';
15
16
constructor(private http: HttpClient) {}
17
11
providedIn: 'root'
12
})
13
export class BookStoreService {
14
+ private api = 'https://api3.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,20 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent } from '@angular/common/http';
3
+ import { Observable } from 'rxjs';
4
+
5
+ @Injectable()
6
+ export class TokenInterceptor implements HttpInterceptor {
7
+ private authToken = '1234567890';
8
+
9
+ intercept(
10
+ request: HttpRequest<any>,
11
+ next: HttpHandler
12
+ ): Observable<HttpEvent<any>> {
13
+ const newRequest = request.clone({
14
+ setHeaders: {
15
+ Authorization: `Bearer ${this.authToken}`
16
+ }
17
+ });
18
+ return next.handle(newRequest);
19
+ }
20
+ }