backend-scaffold-cli 1.8.0 → 1.9.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.
- package/bin/cli.js +9 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -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
|
|
@@ -400,11 +401,13 @@ module.exports=limiter;
|
|
|
400
401
|
const { ErrorHandler } = require('./errorHandler');
|
|
401
402
|
|
|
402
403
|
const authenticateToken = (req, res, next) => {
|
|
403
|
-
const
|
|
404
|
+
const authHeader = req.headers.authorization;
|
|
404
405
|
|
|
405
|
-
if (
|
|
406
|
-
return next(new ErrorHandler('
|
|
406
|
+
if(!authHeader || !authHeader.startsWith('Bearer ')){
|
|
407
|
+
return next(new ErrorHandler('Authorization header is missing or malformed', 401));
|
|
407
408
|
}
|
|
409
|
+
const token = authHeader.split(' ')[1];
|
|
410
|
+
|
|
408
411
|
|
|
409
412
|
try {
|
|
410
413
|
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
|
@@ -670,7 +673,8 @@ function createUserModel(projectPath) {
|
|
|
670
673
|
if (!this.isModified('password')) {
|
|
671
674
|
return next();
|
|
672
675
|
}
|
|
673
|
-
|
|
676
|
+
const salt = Number(process.env.BCRYPT_SALT_ROUNDS || 10);
|
|
677
|
+
this.password = await bcrypt.hash(this.password,salt);
|
|
674
678
|
next();
|
|
675
679
|
});
|
|
676
680
|
|
|
@@ -719,7 +723,7 @@ function createAuthController(projectPath) {
|
|
|
719
723
|
}
|
|
720
724
|
|
|
721
725
|
const user= await User.create({name,email,password});
|
|
722
|
-
const
|
|
726
|
+
const token= generateToken(user._id);
|
|
723
727
|
|
|
724
728
|
res.status(201).json({
|
|
725
729
|
success:true,
|