This repository has been archived on 2024-07-10. You can view files and clone it, but cannot push or open issues or pull requests.
backend/utils/jwtToken.js
2023-09-13 23:36:17 +07:00

22 lines
480 B
JavaScript

// Create and send token and save in the cookie.
const sendToken = (user, statusCode, res) => {
// Create Jwt token
const token = user.getJwtToken();
// Options for cookie
const options = {
expires: new Date(
Date.now() + 7 * 24 * 60 * 60 * 1000
),
httpOnly: true
}
res.status(statusCode).cookie('token', token, options).json({
success: true,
token,
user
});
}
module.exports = sendToken;