mirror of
https://gitlab.com/little-lines/backend.git
synced 2025-07-07 14:31:04 +00:00
login logout
This commit is contained in:
parent
24e7aa1ad0
commit
f1f614d4e7
6 changed files with 207 additions and 0 deletions
|
@ -0,0 +1,22 @@
|
|||
// 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;
|
Loading…
Add table
Add a link
Reference in a new issue