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: '[email protected]',
          pass: 'password'
        }
        });
    
        var mailOptions = {
          from: '[email protected]',
          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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.