remove unused comments
This commit is contained in:
parent
f71d48bea9
commit
d1a2d309ad
3 changed files with 3 additions and 7 deletions
|
@ -4,7 +4,7 @@ const UserModel = require("../models/userModel");
|
||||||
const { sendResponse } = require("../middlewares/responses");
|
const { sendResponse } = require("../middlewares/responses");
|
||||||
const env = require("../helpers/Env");
|
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) {
|
async function registerUser(req, res) {
|
||||||
try {
|
try {
|
||||||
|
@ -45,7 +45,6 @@ async function loginUser(req, res) {
|
||||||
const token = jwt.sign({ id: user._id }, secretKey, {
|
const token = jwt.sign({ id: user._id }, secretKey, {
|
||||||
expiresIn: "1h",
|
expiresIn: "1h",
|
||||||
});
|
});
|
||||||
// Set the token as a cookie in the response header
|
|
||||||
res.setHeader("Set-Cookie", `token=${token}; HttpOnly; Max-Age=3600`); // 1 hour
|
res.setHeader("Set-Cookie", `token=${token}; HttpOnly; Max-Age=3600`); // 1 hour
|
||||||
sendResponse(res, 200, { token });
|
sendResponse(res, 200, { token });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
const { sendResponse } = require("./responses");
|
const { sendResponse } = require("./responses");
|
||||||
const { parse } = require('cookie'); // Import the 'cookie' package
|
const { parse } = require('cookie');
|
||||||
const env = require("../helpers/Env");
|
const env = require("../helpers/Env");
|
||||||
|
|
||||||
function isAuthenticated(req, res, next) {
|
function isAuthenticated(req, res, next) {
|
||||||
// Use the 'cookie' package to parse cookies from the request header
|
|
||||||
const cookies = parse(req.headers.cookie || '');
|
const cookies = parse(req.headers.cookie || '');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = cookies.token; // Access the 'token' cookie
|
const token = cookies.token;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return sendResponse(res, 401, { error: "Authentication failed" });
|
return sendResponse(res, 401, { error: "Authentication failed" });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// server.js
|
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
Loading…
Reference in a new issue