From 059cf89acf8312be9f39c17d21c42294e546fc24 Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Wed, 25 May 2022 01:03:19 +0700 Subject: [PATCH] update --- application/middlewares/jwt.middleware.js | 4 ++-- application/modules/auth/auth.controller.js | 13 ++++++------- .../modules/loadbalance/loadbalance.controller.js | 2 +- .../reservebalance/reservebalance.controller.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/application/middlewares/jwt.middleware.js b/application/middlewares/jwt.middleware.js index 4649610..b31218c 100644 --- a/application/middlewares/jwt.middleware.js +++ b/application/middlewares/jwt.middleware.js @@ -8,11 +8,11 @@ const generateRefreshToken = (req) => { }; const authenticateRefreshToken = (req, res, next) => { - jwt.verify(req.body.refresh_token, process.env.REFRESH_TOKEN_SECRET, (err, data) => { + jwt.verify(req.header("refresh_token"), process.env.REFRESH_TOKEN_SECRET, (err, data) => { if (err) { return res.json({ code: "01", - message: "Refresh Token is invalid. "+err+". Please login!", + message: "Refresh Token is invalid. Please login!", data: {}, }); } diff --git a/application/modules/auth/auth.controller.js b/application/modules/auth/auth.controller.js index b19d980..6e2a871 100644 --- a/application/modules/auth/auth.controller.js +++ b/application/modules/auth/auth.controller.js @@ -33,10 +33,6 @@ const validate = (method) => { return [ body("mid").not().isEmpty().withMessage("MID is required"), body("tid").not().isEmpty().withMessage("TID is required"), - body("refresh_token") - .not() - .isEmpty() - .withMessage("Refresh Token is required"), ]; } } @@ -78,7 +74,10 @@ const login = async (req, res, next) => { } // check password - let checkPassword = await bcrypt.compare(password, checkDataLogin.c_password_hash); + let checkPassword = await bcrypt.compare( + password, + checkDataLogin.c_password_hash + ); if (!checkPassword) { return res.status(200).json({ code: "01", @@ -190,11 +189,11 @@ const register = async (req, res) => { } }; - // REFRESH TOKEN const refreshToken = async (req, res) => { try { - const { mid, tid, refresh_token } = req.body; + const { mid, tid } = req.body; + const refresh_token = req.header("refresh_token"); // validate const err = validationResult(req); diff --git a/application/modules/loadbalance/loadbalance.controller.js b/application/modules/loadbalance/loadbalance.controller.js index a640130..635ede2 100644 --- a/application/modules/loadbalance/loadbalance.controller.js +++ b/application/modules/loadbalance/loadbalance.controller.js @@ -379,7 +379,7 @@ const inquiryLoadingBalance = async (req, res) => { return res.status(200).json({ code: "01", message: "load balance doesn't exist", - data: {}, + data: [], }); } diff --git a/application/modules/reservebalance/reservebalance.controller.js b/application/modules/reservebalance/reservebalance.controller.js index 28a37f5..a9543cb 100644 --- a/application/modules/reservebalance/reservebalance.controller.js +++ b/application/modules/reservebalance/reservebalance.controller.js @@ -281,7 +281,7 @@ const inquiryReservation = async (req, res) => { return res.status(200).json({ code: "01", message: "reservation doesn't exist", - data: {}, + data: [], }); }