-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
usernameField settings outlined in the docs do not work #360
Comments
For some reason, even
doesn't work for me (getting duplicate username field error). Tried Anyone running into similar issues? |
Up on this issue ? I seem to got it too and I don't see any fixes |
I also have the same issue. From Version: 8.0.0 |
TLDR Try: Brief: Bit of a strange bug. I have multi user login, and it needs Context: Plugin passport-local-mongoose to "userSchema" - set usernameField to "email" In app.js Incoming form contains "email" and "password" fields Authenticate with Using v6.3.0 |
Other than doing this in the user schema:
userSchema.plugin(passportLocalMongoose, { usernameField: 'email' });
(or whatever field you want to use)
In the docs for passport-local-mongoose it says to replace this:
passport.use(new LocalStrategy(User.authenticate()));
with this:
if you want to use a different field for username.
It says directly below this:
However, this does not work at all.
Upon user creation, the first user would work fine, however, subsequent attempts would come back with an error about a duplicate field "username" of "null."
I may have been doing something wrong, but I was following the docs as best as I could. In order to get this to work for me, I had to do this:
NOT
passport.use(User.createStrategy());
OR
passport.use(new LocalStrategy(User.authenticate()));
I also tried this, as it says to replace User.authenticate() with User.createStrategy(). So I took that literally and tried this but also does not work (crashes app because LocalStrategy needs a callback function)
passport.use(new LocalStrategy(User.createStrategy()));
The text was updated successfully, but these errors were encountered: