You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
427 B
JavaScript
18 lines
427 B
JavaScript
1 year ago
|
import jwt from 'jsonwebtoken'
|
||
|
|
||
|
const generateToken = (res, userId) => {
|
||
|
const token = jwt.sign({userId}, process.env.JWT_SECRET, { expiresIn: "30d"})
|
||
|
|
||
|
// Set JWT as HTTP-Only Cookie
|
||
|
res.cookie('jwt', token, {
|
||
|
httpOnly: true,
|
||
|
secure: process.env.NODE_ENV !== 'development',
|
||
|
sameSite: 'strict',
|
||
|
maxAge: 30 * 24 * 60 * 60 * 100
|
||
|
})
|
||
|
|
||
|
return token
|
||
|
|
||
|
}
|
||
|
|
||
|
export default generateToken
|