JWT Authentication

JSON Web Tokens (JWT) are used for secure authentication.

Snippet:

const jwt = require("jsonwebtoken"); const token = jwt.sign({ userId: 123 }, "secretKey", { expiresIn: "1h" });

Example:

const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET, { expiresIn: "1d" });