cms
This commit is contained in:
parent
1f8ce68594
commit
cbe3ed236b
@ -4,12 +4,12 @@ const sendToken = (user, statusCode, res) => {
|
|||||||
const token = user.getJWTToken();
|
const token = user.getJWTToken();
|
||||||
// consolelog(token)
|
// consolelog(token)
|
||||||
//options for cookie
|
//options for cookie
|
||||||
const options = {
|
// const options = {
|
||||||
expires: new Date(
|
// expires: new Date(
|
||||||
Date.now() + 20 * 24 * 60 * 60 * 1000
|
// Date.now() + 20 * 24 * 60 * 60 * 1000
|
||||||
),
|
// ),
|
||||||
httpOnly: true,
|
// httpOnly: true,
|
||||||
};
|
// };
|
||||||
|
|
||||||
res.status(statusCode).cookie("token", token).json({
|
res.status(statusCode).cookie("token", token).json({
|
||||||
// res.status(statusCode).json({
|
// res.status(statusCode).json({
|
||||||
|
@ -4,7 +4,7 @@ import ErrorHander from "../Utils/errorhander.js"
|
|||||||
|
|
||||||
export const isAuthenticatedUser = async (req, res, next) => {
|
export const isAuthenticatedUser = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
// const { token } = req.cookies;
|
|
||||||
if (!req.headers.authorization) {
|
if (!req.headers.authorization) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
@ -17,6 +17,7 @@ export const isAuthenticatedUser = async (req, res, next) => {
|
|||||||
//remove Bearer from token
|
//remove Bearer from token
|
||||||
const fronttoken = getToken.authorization.slice(7);
|
const fronttoken = getToken.authorization.slice(7);
|
||||||
|
|
||||||
|
|
||||||
const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET);
|
const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET);
|
||||||
|
|
||||||
const fuser = await User.findById(frontdecoded.id);
|
const fuser = await User.findById(frontdecoded.id);
|
||||||
|
@ -65,7 +65,7 @@ userSchema.pre("save", async function (next) {
|
|||||||
// JWT TOKEN
|
// JWT TOKEN
|
||||||
userSchema.methods.getJWTToken = function () {
|
userSchema.methods.getJWTToken = function () {
|
||||||
return jwt.sign({ id: this._id }, process.env.JWT_SECRET, {//make token
|
return jwt.sign({ id: this._id }, process.env.JWT_SECRET, {//make token
|
||||||
expiresIn: "1d",
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// console.log(process.env.JWT_SECRET)
|
// console.log(process.env.JWT_SECRET)
|
||||||
|
Loading…
Reference in New Issue
Block a user