Skip to main content

Posts

Showing posts from January 1, 2023

How to Generate JWT Token with Signup API - Node JS, Express JS

  // install dependency  jwt using command  npm install jsonwebtoken at your folder terminal  // import it in your app.js  // Use this code in file in which you are saving user to database or you are receiving result of successfully registered user . in my case am getting result from Indexcontroller (You can make your own controller to save data)  =====================================================================  //API to register new User with jWT Token import jwt from 'jsonwebtoken';  router.post("/register",(req,res)=>{     IndexController.registerUser(req.body).then((result)=>{            let jwttoken;       jwttoken = jwt.sign({ _id: result._id, email: result.email },"8Zzvasu5tw0Ionm3XPZZfN0NOml3z9FMfmpgXwovR9fp6ryDIoGRM8EPHAB6iHsc0fb",{ expiresIn: "1h" });      res.status(201).json({success: true,data: { _id: result._id, email: result.email, jwttok...

How to Generate unique verification link to get verify user once - Node js , Express Js

// Only Logic code included - modify according to your project  // do basic things create app.js & create routes, controller and models folder and add files respectively IndexRouter.js , IndexController.js & IndexModel.js    // IndexRouter.js (only logic code added here)  router.post("/register",(req,res)=>{         IndexController.registerUser(req.body).then((result)=>{     var token = result.token; // this token is added from result coming from IndexController       sendEmail(req.body.email,req.body.password,token);       res.render("register",{"output":"User register successfully..."});              //res.status(201).send({ message : "User Logged In"})     }).catch((err)=>{        res.render("register",{"output":err});     //console.log(err);  }); }); ===================== //IndexController.js  start...