From a49ada95570210396ca7610ae03f20b885fd1e17 Mon Sep 17 00:00:00 2001 From: moepoi Date: Sun, 21 Nov 2021 09:27:02 +0700 Subject: [PATCH] Fix product page bug --- routes/index.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/routes/index.js b/routes/index.js index 2511bd4..7ee17af 100644 --- a/routes/index.js +++ b/routes/index.js @@ -194,31 +194,23 @@ router.get("/products", (req, res) => { }); router.get(["/product", "/product/:id"], (req, res) => { - if (!req.params.id) { - auth.session_converter(req.cookies.session_token).then((key) => { - if (key != null) { - controller.getProduct(req.params.id).then((data) => { - if (data != undefined) { - res.render("pages/product", { - data: data, - loggedIn: 'true' - }); - } else { - res.redirect("/products"); - } + auth.session_converter(req.cookies.session_token).then((key) => { + if (key != null) { + controller.getProduct(req.params.id).then((data) => { + res.render("pages/product", { + data: data, + loggedIn: 'true' }); - } else { - controller.getProduct(req.params.id).then((data) => { - res.render("pages/product", { - data: data, - loggedIn: 'false' - }); + }); + } else { + controller.getProduct(req.params.id).then((data) => { + res.render("pages/product", { + data: data, + loggedIn: 'false' }); - } - }); - } else { - res.redirect("/products") - } + }); + } + }); }); router.get("/bag", (req, res) => {