From 1ce0d02b7281c37ce7491ae29e211b776d159841 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 10 Mar 2020 00:20:32 +0100 Subject: [PATCH] Use new mustBeAuthenticated middleware. --- api/subscriptions.js | 9 +++------ api/update.js | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/api/subscriptions.js b/api/subscriptions.js index 087f48a..c79779c 100644 --- a/api/subscriptions.js +++ b/api/subscriptions.js @@ -9,6 +9,8 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { useNewUrlParser: true }); +const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated")) + const config = require(path.join(__dirname + "/../config/defaults/push")); const Subscription = require(path.join(__dirname + "/../schemas/Subscription")); const lotteryConfig = require(path.join( @@ -67,12 +69,7 @@ const saveToDatabase = async subscription => { } }; -router.route("/send-notification").post(async (req, res) => { - if (!req.isAuthenticated()) { - res.send(false); - return; - } - +router.route("/send-notification").post(mustBeAuthenticated, async (req, res) => { const message = JSON.stringify({ message: req.body.message, title: "Vinlotteri!" diff --git a/api/update.js b/api/update.js index ec1b130..8a080ac 100644 --- a/api/update.js +++ b/api/update.js @@ -7,6 +7,7 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { }); const sub = require(path.join(__dirname + "/../api/subscriptions")); +const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated")) const Subscription = require(path.join(__dirname + "/../schemas/Subscription")); const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); @@ -20,11 +21,7 @@ router.use((req, res, next) => { next(); }); -router.route("/log/wines").post(async (req, res) => { - if (!req.isAuthenticated()) { - res.send(false); - return; - } +router.route("/log/wines").post(mustBeAuthenticated, async (req, res) => { const wines = req.body; for (let i = 0; i < wines.length; i++) { let wine = wines[i]; @@ -57,6 +54,7 @@ router.route("/log").post(async (req, res) => { return; } +router.route("/log").post(mustBeAuthenticated, async (req, res) => { await PreLotteryWine.deleteMany(); const purchaseBody = req.body.purchase;