UNPKG

mern-scaffold

Version:

mern-scaffold is a CLI tool that helps you to quickly develop basic boilerplate code for your MERN app. You can generate boilerplate code for your Frontend or Backend. You can also generate them as a full stack project.

25 lines (21 loc) 748 B
// Import the 'jsonwebtoken' library. const jwt = require('jsonwebtoken'); /** * Asynchronously generates a JSON Web Token (JWT) using the provided user information. * * @param {Object} userInfo The user information to include in the JWT. * @returns {string} The generated JWT. */ const generateJwtToken = async (userInfo) => { // Sign the JWT using the user information, a secret key, and an expiration time. // The secret key and expiration time are stored in environment variables. const token = await jwt.sign(userInfo, process.env.JWT_SECRET_KEY, { expiresIn: process.env.JWT_EXPIRE, }); // Return the generated JWT. return token; }; // Export the 'generateJwtToken' function. module.exports = { generateJwtToken, };