Use password values from the constant folder + changed the name of the isAuthorized function + Remove :/id from the change-password endpoint
This commit is contained in:
@@ -364,7 +364,11 @@ const changePassword = async (req, res) => {
|
||||
}
|
||||
|
||||
// check if the new password is strong
|
||||
if (['Too weak', 'Weak'].includes(checkPasswordStrength(newPassword))) {
|
||||
if (
|
||||
[apiConstants.PASSWORD.TOO_WEAK, apiConstants.PASSWORD.WEAK].includes(
|
||||
checkPasswordStrength(newPassword),
|
||||
)
|
||||
) {
|
||||
return res.status(400).send({
|
||||
message: 'This password is weak, please use another password',
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const config = require('../config');
|
||||
const { decodeToken } = require('../utils/index');
|
||||
|
||||
const isAuthorized = async (req, res, next) => {
|
||||
const isAuthenticated = async (req, res, next) => {
|
||||
try {
|
||||
// extract the payload from the token and verify it
|
||||
const payload = await decodeToken(
|
||||
@@ -17,4 +17,4 @@ const isAuthorized = async (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { isAuthorized };
|
||||
module.exports = { isAuthenticated };
|
||||
|
||||
@@ -3,7 +3,7 @@ const express = require('express');
|
||||
const controllers = require('../controllers/auth');
|
||||
const { validator } = require('../middlewares/validation');
|
||||
const schema = require('../schemas/auth');
|
||||
const { isAuthorized } = require('../middlewares/auth');
|
||||
const { isAuthenticated } = require('../middlewares/auth');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -20,9 +20,9 @@ router.get(
|
||||
);
|
||||
|
||||
router.put(
|
||||
'/:userId/change-password',
|
||||
'/change-password',
|
||||
validator(schema.changePassword),
|
||||
isAuthorized,
|
||||
isAuthenticated,
|
||||
controllers.changePassword,
|
||||
);
|
||||
|
||||
|
||||
@@ -495,16 +495,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/auth/{userId}/change-password": {
|
||||
"/api/auth/change-password": {
|
||||
"put": {
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "userId",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
|
||||
Reference in New Issue
Block a user