diff --git a/Utils/jwtToken.js b/Utils/jwtToken.js index e2fd075..f0a5a14 100644 --- a/Utils/jwtToken.js +++ b/Utils/jwtToken.js @@ -4,12 +4,12 @@ const sendToken = (user, statusCode, res) => { const token = user.getJWTToken(); // consolelog(token) //options for cookie - const options = { - expires: new Date( - Date.now() + 20 * 24 * 60 * 60 * 1000 - ), - httpOnly: true, - }; + // const options = { + // expires: new Date( + // Date.now() + 20 * 24 * 60 * 60 * 1000 + // ), + // httpOnly: true, + // }; res.status(statusCode).cookie("token", token).json({ // res.status(statusCode).json({ diff --git a/middlewares/auth.js b/middlewares/auth.js index 5762e45..16e7342 100644 --- a/middlewares/auth.js +++ b/middlewares/auth.js @@ -4,7 +4,7 @@ import ErrorHander from "../Utils/errorhander.js" export const isAuthenticatedUser = async (req, res, next) => { try { - // const { token } = req.cookies; + if (!req.headers.authorization) { return res.status(400).json({ success: false, @@ -17,6 +17,7 @@ export const isAuthenticatedUser = async (req, res, next) => { //remove Bearer from token const fronttoken = getToken.authorization.slice(7); + const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET); const fuser = await User.findById(frontdecoded.id); diff --git a/models/userModel.js b/models/userModel.js index 7549c82..8321baf 100644 --- a/models/userModel.js +++ b/models/userModel.js @@ -65,7 +65,7 @@ userSchema.pre("save", async function (next) { // JWT TOKEN userSchema.methods.getJWTToken = function () { return jwt.sign({ id: this._id }, process.env.JWT_SECRET, {//make token - expiresIn: "1d", + }); }; // console.log(process.env.JWT_SECRET)