DEV Community

Discussion on: Building a Secure Authentication API with TypeScript, Node.js, and MongoDB

Collapse
 
temuuder_baatar_8537c50af profile image
Temuuder Baatar

this is log when i installed:
npm install bcryptjs cors dotenv express helmet jsonwebtoken mongoose morgan nodemailer zod && npm install -D @types/bcryptjs @types/cors @types/express @types/helmet @types/jsonwebtoken @types/mongoose @types/morgan @types/nodemailer ts-node-dev typescript

Image description

Collapse
 
fredabod profile image
FredAbod

I think the error might be from your config file, can you try this approach just to be sure, that you have your jwt files properly called

  // Ensure JWT secret is defined
    const jwtSecret = config.jwt.secret || "2e6767eed71s72s";
    if (!jwtSecret) {
      res.status(500).json({
        status: "error",
        message: "JWT secret is missing",
      });
      return;
    }

    // Generate JWT token
    const token = jwt.sign({ userId: user._id.toString() }, jwtSecret, {
      expiresIn: config.jwt.expiresIn || "1h", // Default to 1 hour if undefined
    });
Enter fullscreen mode Exit fullscreen mode