Skip to content

Commit 3f2c91f

Browse files
author
Your Name
committed
Stripe In Practice Course
1 parent 7bb4947 commit 3f2c91f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/app/services/checkout.service.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {Injectable} from '@angular/core';
2-
import {HttpClient} from '@angular/common/http';
2+
import {HttpClient, HttpHeaders} from '@angular/common/http';
33
import {Observable} from 'rxjs';
44
import {CheckoutSession} from '../model/checkout-session.model';
5+
import {AngularFireAuth} from '@angular/fire/auth';
56

67
declare const Stripe;
78

@@ -11,15 +12,23 @@ declare const Stripe;
1112
})
1213
export class CheckoutService {
1314

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);
1521

1622
}
1723

1824
startCourseCheckoutSession(courseId:string): Observable<CheckoutSession> {
25+
26+
const headers = new HttpHeaders().set("Authorization", this.jwtAuth);
27+
1928
return this.http.post<CheckoutSession>("/api/checkout", {
2029
courseId,
2130
callbackUrl: this.buildCallbackUrl()
22-
})
31+
}, {headers})
2332
}
2433

2534
buildCallbackUrl() {

0 commit comments

Comments
 (0)