Skip to content
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

options.usernameQueryFields needs to be set to default empty array #357

Open
thisancog opened this issue Jun 4, 2022 · 3 comments
Open

Comments

@thisancog
Copy link

thisancog commented Jun 4, 2022

When the option 'usernameQueryFields' is specified by the user, the following error occurs:

…/passport-local-mongoose/index.js:36
options.usernameQueryFields.push(options.usernameField);
TypeError: options.usernameQueryFields.push is not a function

This should be solved by initiating options.usernameQueryFields in index.js as such:

options.usernameQueryFields = [];

@saintedlama
Copy link
Owner

As option usernameQueryFields should be provided as an array or in case not provided is prepopulated as an array I don't see the issue here. Perhaps a type check for isArray after line 35 would make sense to prevent problems

@saintedlama
Copy link
Owner

In

usernameQueryFields: Array<string>;
that option is defined as an array of strings, so I don't even see an issue when using typescript.

@samuelchika
Copy link

i am using the email as the username in my code, I also added the plugin into the schema as defined in the doc.
I am trying to authenticate, but its not working.
Its doing the redirecting to the failed route define in the redirect.

UserSchema.plugin(passportLocalMongoose, {
usernameField: "email",
usernameQueryFields: ["email", "password"],
usernameUnique: true,

The login route is as below
router.post("/login", passport.authenticate("local", { failureRedirect: "/auth/login/failed" }), (req, res) => {
res.send("Wawou");
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants