Skip to content

Commit 95b5d95

Browse files
committed
Typescript Bootcamp
1 parent 1a7c2c9 commit 95b5d95

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {NextFunction, Request, Response} from "express";
2+
3+
export function checkIfAuthenticated(
4+
request: Request, response: Response, next:NextFunction
5+
) {
6+
7+
8+
}

rest-api/src/server.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {createCourse} from "./routes/create-course";
2222
import {deleteCourseAndLessons} from "./routes/delete-course";
2323
import {createUser} from "./routes/create-user";
2424
import {login} from "./routes/login";
25+
import {checkIfAuthenticated} from "./middlewares/authentication-middleware";
2526

2627
const cors = require("cors");
2728

@@ -38,19 +39,19 @@ function setupExpress() {
3839

3940
app.route("/").get(root);
4041

41-
app.route("/api/courses").get(getAllCourses);
42+
app.route("/api/courses").get(checkIfAuthenticated, getAllCourses);
4243

43-
app.route("/api/courses/:courseUrl").get(findCourseByUrl);
44+
app.route("/api/courses/:courseUrl").get(checkIfAuthenticated, findCourseByUrl);
4445

45-
app.route("/api/courses/:courseId/lessons").get(findLessonsForCourse);
46+
app.route("/api/courses/:courseId/lessons").get(checkIfAuthenticated, findLessonsForCourse);
4647

47-
app.route("/api/courses/:courseId").patch(updateCourse);
48+
app.route("/api/courses/:courseId").patch(checkIfAuthenticated, updateCourse);
4849

49-
app.route("/api/courses").post(createCourse);
50+
app.route("/api/courses").post(checkIfAuthenticated, createCourse);
5051

51-
app.route("/api/courses/:courseId").delete(deleteCourseAndLessons);
52+
app.route("/api/courses/:courseId").delete(checkIfAuthenticated, deleteCourseAndLessons);
5253

53-
app.route("/api/users").post(createUser);
54+
app.route("/api/users").post(checkIfAuthenticated, createUser);
5455

5556
app.route("/api/login").post(login);
5657

0 commit comments

Comments
 (0)