Skip to content

Commit

Permalink
feat: adjusted the branche
Browse files Browse the repository at this point in the history
  • Loading branch information
abdinasir-Tman committed Mar 10, 2024
1 parent 835c7a0 commit 05a8784
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ JWT_SECRET_KEY=
# This setting can influence the application's behavior, enabling or disabling certain features based on the environment.
# For example, in 'development' mode, more verbose logging might be enabled, whereas 'production' might focus on performance optimizations and error handling.
# Default: development (if not specified)
NODE_ENVIRONMENT=
NODE_ENVIRONMENT=
6 changes: 3 additions & 3 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export async function registerUser(req, res) {
return res.status(400).json({ message: "User already exists" });
}
// Hash the password before saving it
const hashed = await hashPassword(password);
// Create a new user instance with the hashed password and save it to the database
user = new User({ email, password: hashed });
const hashedPassword = await hashPassword(password);
// Create a new user instance and save it to the database
user = new User({ email, password: hashedPassword });
await user.save();
// Respond with the generated token
res.status(201).json({ message: "User created successfully" });
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import jwt from "jsonwebtoken";
import { jwtSecret } from "../config/initialConfig.js";

// Middleware to validate JWT tokens
export default function auth(req, res, next) {
Expand All @@ -12,7 +13,7 @@ export default function auth(req, res, next) {

try {
// Verify the token using the secret key
const decoded = jwt.verify(token, process.env.JWT_SECRET);
const decoded = jwt.verify(token, jwtSecret);
req.user = decoded.userId; // Attach the user ID to the request object
next(); // Proceed to the next middleware or route handler
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion src/models/User.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Import required modules and configuration
import mongoose from "mongoose";
import bcrypt from "bcrypt";

// Define a schema for the user with email and password fields
const UserSchema = new mongoose.Schema({
Expand Down

0 comments on commit 05a8784

Please sign in to comment.