Skip to content

Commit

Permalink
fx<Auth>:fixed jwt expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-py committed May 2, 2024
1 parent db4d905 commit 5d3941e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
40 changes: 21 additions & 19 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,25 @@ const sendTokenResponse = (user, statusCode, res) => {
? user[0].getSignedJwtToken()
: user.getSignedJwtToken();

const options = {
expires: new Date(
Date.now() + process.env.JWT_COOKIE_EXPIRE * 24 * 60 * 60
),
httpOnly: true
};

if (process.env.NODE_ENV === 'production') {
options.secure = true;
}

return res
.status(statusCode)
.cookie('token', token, options)
.json({
success: true,
token,
user: Array.isArray(user) ? user[0] : user
});
// const options = {
// expires: new Date(
// Date.now() + process.env.JWT_COOKIE_EXPIRE * 24 * 60 * 60
// ),
// httpOnly: true
// };

// if (process.env.NODE_ENV === 'production') {
// options.secure = true;
// }

return (
res
.status(statusCode)
// .cookie('token', token, options)
.json({
success: true,
token,
user: Array.isArray(user) ? user[0] : user
})
);
};
3 changes: 2 additions & 1 deletion model/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ userSchema.methods.getSignedJwtToken = function () {
{
user_id: this._id
},
process.env.JWT_SECRET
process.env.JWT_SECRET,
{ expiresIn: '30 days' }
);
};

Expand Down

0 comments on commit 5d3941e

Please sign in to comment.