1

I am using passport magic email verification feature (refering from https://github.com/mxstbr/passport-magic-login) this is my code


    const magicLogin = new MagicLoginStrategy({
     
      secret: "process.env.MAGIC_LINK_SECRET",
    
      callbackUrl: "/auth/magiclogin/callback",
      sendMagicLink: async (destination, href) => {
        var link = 'http://localhost:3000' + href;
        var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: 'frommail@gmail.com',
          pass: 'password'
        }
        });
    
        var mailOptions = {
          from: 'frommail@gmail.com',
          to: destination,
          subject: 'Projectcomm Signin email',
          text: 'Hello! Click the link below to finish signing in to 
       Todos.\r\n\r\n' + link,
        };
    
        transporter.sendMail(mailOptions, function(error, info){
          if (error) {
            console.log(error);
          } else {
            console.log('Email sent: ' + info.response);
    
          }
        });
      },
    
      verify: (payload, callback) => {
        // Get or create a user with the provided email from the 
     database
        User.find({email:payload.destination})
          .then(user => {
            if(user){
              return callback(null, user)
            }
            if(!user){
              const newuser = new User({
                email:payload.destination
              })
              newuser.save();
              callback(null, newuser);
            }
          })
          .catch(err => {
            callback(err)
          })
      }
    });
    passport.use(magicLogin);
    app.post('/auth/magiclogin', magicLogin.send, function (req, res, 
   next) {
    
    });
    app.get("/authenticate/email/verify", 
   passport.authenticate("magiclogin"),(req,res)=>{
      console.log("authenticates");
    });

const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose');

const userSchema = new mongoose.Schema({
  //schema here
});

userSchema.plugin(passportLocalMongoose, {usernameQueryFields: ["email"]});
const User = new mongoose.model('User',userSchema);

module.exports = User;

but i am getting the below error

TypeError: user.get is not a function at C:\Users\mypc\Desktop\projectpath\node_modules\passport-local-mongoose\index.js:212:21

how can i solve it, I even Tried to use old version.

Ritesh
  • 27
  • 5

0 Answers0