diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 8354f70..167648b 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -4,7 +4,7 @@ const UserModel = require("../models/userModel"); const { sendResponse } = require("../middlewares/responses"); const env = require("../helpers/Env"); -const secretKey = env.get("JWT_KEY"); // Replace with your own secret key +const secretKey = env.get("JWT_KEY"); async function registerUser(req, res) { try { @@ -45,7 +45,6 @@ async function loginUser(req, res) { const token = jwt.sign({ id: user._id }, secretKey, { expiresIn: "1h", }); - // Set the token as a cookie in the response header res.setHeader("Set-Cookie", `token=${token}; HttpOnly; Max-Age=3600`); // 1 hour sendResponse(res, 200, { token }); } catch (error) { diff --git a/src/middlewares/auth.js b/src/middlewares/auth.js index e65293a..da824f2 100644 --- a/src/middlewares/auth.js +++ b/src/middlewares/auth.js @@ -1,14 +1,13 @@ const jwt = require("jsonwebtoken"); const { sendResponse } = require("./responses"); -const { parse } = require('cookie'); // Import the 'cookie' package +const { parse } = require('cookie'); const env = require("../helpers/Env"); function isAuthenticated(req, res, next) { - // Use the 'cookie' package to parse cookies from the request header const cookies = parse(req.headers.cookie || ''); try { - const token = cookies.token; // Access the 'token' cookie + const token = cookies.token; if (!token) { return sendResponse(res, 401, { error: "Authentication failed" }); } diff --git a/src/server.js b/src/server.js index a76b8ad..e03859f 100644 --- a/src/server.js +++ b/src/server.js @@ -1,5 +1,3 @@ -// server.js - const http = require('http'); const url = require('url'); const fs = require('fs');