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:
AbegaM
2024-03-08 17:19:22 +03:00
parent 64af47f1ce
commit 1653e9c9d8
4 changed files with 11 additions and 13 deletions

View File

@@ -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',
});

View File

@@ -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 };

View File

@@ -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,
);

View File

@@ -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",