This commit is contained in:
pawan-dot 2022-11-01 15:32:38 +05:30
parent 1f8ce68594
commit cbe3ed236b
3 changed files with 9 additions and 8 deletions

View File

@ -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({

View File

@ -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);

View File

@ -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)