Skip to content

Commit ece8168

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

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

server/get-user.middleware.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import {Request, Response, NextFunction} from 'express';
3+
4+
5+
export function getUserMiddleware(req: Request, res: Response, next: NextFunction) {
6+
7+
const jwt = req.headers.authorization;
8+
9+
if (jwt) {
10+
11+
}
12+
else {
13+
next();
14+
}
15+
}

server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as express from 'express';
33
import {Application} from "express";
44
import {createCheckoutSession} from './checkout.route';
5+
import {getUserMiddleware} from './get-user.middleware';
56

67

78

@@ -16,7 +17,7 @@ export function initServer() {
1617
});
1718

1819
app.route("/api/checkout").post(
19-
bodyParser.json(), createCheckoutSession);
20+
bodyParser.json(), getUserMiddleware, createCheckoutSession);
2021

2122
const PORT = process.env.PORT || 9000;
2223

0 commit comments

Comments
 (0)