File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
- import { HttpClient } from '@angular/common/http' ;
2
+ import { HttpClient , HttpHeaders } from '@angular/common/http' ;
3
3
import { Observable } from 'rxjs' ;
4
4
import { CheckoutSession } from '../model/checkout-session.model' ;
5
+ import { AngularFireAuth } from '@angular/fire/auth' ;
5
6
6
7
declare const Stripe ;
7
8
@@ -11,15 +12,23 @@ declare const Stripe;
11
12
} )
12
13
export class CheckoutService {
13
14
14
- constructor ( private http :HttpClient ) {
15
+ private jwtAuth :string ;
16
+
17
+ constructor ( private http :HttpClient ,
18
+ private afAuth : AngularFireAuth ) {
19
+
20
+ afAuth . idToken . subscribe ( jwt => this . jwtAuth = jwt ) ;
15
21
16
22
}
17
23
18
24
startCourseCheckoutSession ( courseId :string ) : Observable < CheckoutSession > {
25
+
26
+ const headers = new HttpHeaders ( ) . set ( "Authorization" , this . jwtAuth ) ;
27
+
19
28
return this . http . post < CheckoutSession > ( "/api/checkout" , {
20
29
courseId,
21
30
callbackUrl : this . buildCallbackUrl ( )
22
- } )
31
+ } , { headers } )
23
32
}
24
33
25
34
buildCallbackUrl ( ) {
You can’t perform that action at this time.
0 commit comments