saintedlama / passport-local-mongoose

Passport-Local Mongoose is a Mongoose plugin that simplifies building username and password login with Passport
MIT License
1.17k stars 295 forks source link

.createSession(), verify callback error #269

Open puzzledbytheweb opened 6 years ago

puzzledbytheweb commented 6 years ago

Hello everyone!

I am trying to use this authentication method in a React app with an Express backend. When defining the local strategy I use the .createSession() static method.

LocalStrategy throws this error: TypeError: LocalStrategy requires a verify callback

This is how I am calling it:

passport.use(new LocalStrategy(User.createStrategy()))

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser()); 

Moreover I can't understant where should I set the usernameField to 'email'

Is it like this? User.createStrategy({ usernameField: 'email'})

I am a bit confused about this...

Thanks in advance!

JosephmBassey commented 6 years ago

Hi there , in your model,


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

const userSchema = new Schema({
   ...
});
userSchema.plugin(passportLocalMongoose, { usernameField: 'email' });
module.exports = mongoose.model('User', userSchema);```