backend-scaffold-cli 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +11 -15
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -48,7 +48,7 @@ program
48
48
  type: 'confirm',
49
49
  name: 'useFileUpload',
50
50
  message: 'Include file upload support (multer)?',
51
- default: true
51
+ default: false
52
52
  },
53
53
  {
54
54
  type: 'confirm',
@@ -198,6 +198,7 @@ ${answers.useDNSFix ? '\n# DNS Configuration (for MongoDB connection issues)\nDN
198
198
  # JWT Configuration
199
199
  JWT_SECRET=your-secret-key-change-this-in-production
200
200
  JWT_EXPIRE=7d
201
+ ${answers.useAuth ? 'BCRYPT_SALT_ROUNDS=10' : ''}
201
202
 
202
203
  # CORS
203
204
  CORS_ORIGIN=http://localhost:3000
@@ -259,15 +260,7 @@ const errorMiddleware = (err, req, res, next) => {
259
260
  err = new ErrorHandler(message, 400);
260
261
  }
261
262
 
262
- if (err.name === 'JsonWebTokenError') {
263
- const message = \`JSON Web Token is invalid, try again\`;
264
- err = new ErrorHandler(message, 400);
265
- }
266
-
267
- if (err.name === 'TokenExpiredError') {
268
- const message = \`JSON Web Token is expired, try again\`;
269
- err = new ErrorHandler(message, 400);
270
- }
263
+
271
264
 
272
265
  res.status(err.statusCode).json({
273
266
  success: false,
@@ -400,11 +393,13 @@ module.exports=limiter;
400
393
  const { ErrorHandler } = require('./errorHandler');
401
394
 
402
395
  const authenticateToken = (req, res, next) => {
403
- const token = req.headers['authorization']?.split(' ')[1];
396
+ const authHeader = req.headers.authorization;
404
397
 
405
- if (!token) {
406
- return next(new ErrorHandler('Access token is missing', 401));
398
+ if(!authHeader || !authHeader.startsWith('Bearer ')){
399
+ return next(new ErrorHandler('Authorization header is missing or malformed', 401));
407
400
  }
401
+ const token = authHeader.split(' ')[1];
402
+
408
403
 
409
404
  try {
410
405
  const decoded = jwt.verify(token, process.env.JWT_SECRET);
@@ -670,7 +665,8 @@ function createUserModel(projectPath) {
670
665
  if (!this.isModified('password')) {
671
666
  return next();
672
667
  }
673
- this.password = await bcrypt.hash(this.password,10);
668
+ const salt = Number(process.env.BCRYPT_SALT_ROUNDS || 10);
669
+ this.password = await bcrypt.hash(this.password,salt);
674
670
  next();
675
671
  });
676
672
 
@@ -719,7 +715,7 @@ function createAuthController(projectPath) {
719
715
  }
720
716
 
721
717
  const user= await User.create({name,email,password});
722
- const tocken= generateToken(user._id);
718
+ const token= generateToken(user._id);
723
719
 
724
720
  res.status(201).json({
725
721
  success:true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-scaffold-cli",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "CLI tool to scaffold Express.js backend projects with MongoDB, middleware, and common setup",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {