cms
This commit is contained in:
parent
1f8ce68594
commit
cbe3ed236b
@ -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({
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user