ExpressJs & PassportJs returning 'missing credentials' on successful login

167
March 21, 2021, at 07:10 AM

I have been trying to solve this for hours, I made everything posts say and still not working. There are another posts in stack overflow about this, but I simply can't find a solution for my code.

It gives me the 'missing credentials' error which comes from badRequesMessage. It just gives me that error when I put the credentials right. When I put them wrong it gives me all the other messages in my code and that works fine. But I can't login and it's weird because it simply stopped working.

okay I'll explain my code a little

I have this route that calls the methdo in AuthController

router.post("/login", AuthController.authUser)

The method is being call is this one

exports.authUser = passport.authenticate('local', {
  successRedirect: '/',
  failureRedirect: '/login',
  failureFlash: true,
})

then my configuration of passport is this one.

passport.use(
  new LocalStrategy(
    {
      usernameField: "email",
      passwordField: "password",
    },
    async (email, password, done) => {
      try {
        const user = await Users.findOne({
          where: {
            email,
          },
        });
            if (!user.verifyPassword(password)) {
          return done(null, false, {
            message: "Password incorrect",
          });
        }
        return done(null, user);
      } catch (error) {
        return done(null, false, {
          message: "the account doesn't exists",
       });
      }
    }
  )
);

passport.serializeUser((user, callback) => {
  callback(null, user);
});
passport.deserializeUser((user, callback) => {
  callback(null, user);
});

this is my form

  form(action="/login" method="POST")
    .field
      label(for="email") Email:
      input(type="email" name="email" placeholder="Email")
    .field
      label(for="password") Password:
      input(type="password" name="password" placeholder="Password")
    .field.
      input.boton(type="submit" value="send")

I hope you can help me with this.

READ ALSO
Django using Celery not performing my task

Django using Celery not performing my task

I have been trying for the past 3 days to get django to perfom asynchronous tasks on a periodic scheduleCame across Celery which seemed like a perfect match for my problem but the more I read online the more problems there seemed to exist that I had prepared

141
Nextcloud: upload large files

Nextcloud: upload large files

I have a Nextcloud 18 on Apache/PHP 73, behind a reverse proxy (out of my control)

186
Getting the contents of more than one DB table in Spring

Getting the contents of more than one DB table in Spring

I'm trying make an endpoint to get the content of two independent tables from my DB using Spring but I've got no idea how to do it

141