Dognation: Password Authentication Project

The more I progress through the back-end part of the Full-Stack path, the more I realize the full aspect of the fiasco.

First of all, all of these lessons about sessions and passport.js and bcrypt are in the wrong place and should be BEFORE this portfolio project: E-Commerce App (REST API).

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Coming back to the subject at hand, this Dognation project is filled with ambiguity and mistakes.

Step 2 and 3 are talking about a verify callback named cb which I’m guessing it’s just the abbreviation of Callback:

Pass in a function with username , password , and the verify callback, cb , as its own parameters.

Make sure to add this function call within the function body of your local strategy:

passport.use(
  new LocalStrategy(function (username, password, cb) {
    // Call to the helper function here
 })
);

CORRECTION:

That is NOT supposed to be cb! It’s supposed to be done. Like so:

passport.use(
  new LocalStrategy(function (username, password, done) {
    // Call to the helper function here
 })
);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In step 10, it wants us to add done as the second parameter of the callback of the helper function helper.findById:

Pass in an the key used to find the user in the DB for the first parameter, and a function with err , and done as parameters for the second one.

CORRECTION:

You should add user as the second parameter of that callback function and NOT done. We already added done in the callback of deserializeUser. Like so:

passport.deserializeUser((id, done) => {
  helper.findById(id, function (err, user) {
    if (err) return done(err);
    return done(null, user);
  })
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

UNRESOLVED ISSUE:

In step 20, when I enter the password incorrectly, I expect to be redirected back to the login page. This endpoint is supposed to do that:

router.post(
  "/login",
  passport.authenticate("local", { failureRedirect: "/login" }),
  (req, res) => {
    res.redirect("../");
});

Yet I get an error in the browser saying that Cannot GET /login

Is anyone having the same issue?

I encountered the same exact issue and had similar frustrations with the inconsistency of this module. While I found the lessons leading up to this project helpful in understanding authentication, the Dognation example needs to be edited.

You did a great job summarizing the issues with the project, so it seems to me that you have grasped the material enough to move forward. I am also stuck at ‘Cannot GET /login’ but have decided to keep moving on.

1 Like

I have some similar problem with that part
Task 20

router.post("/login",
passport.authenticate(‘local’,{failureRedirect: “/login”}), (req, res) => {
res.redirect("…/");
});

but for me i got an error “Error: Unknown authentication strategy “local”” ,i guess it should do something with implementing the LocalStrategy in a different module and never actually import it anywhere there is a commented section for it but i already used “app.use(passport.initialize()); app.use(passport.session());” in app.js and no further instructions were given.
Any ideas?
I would just copy-paste the whole passport.js but can’t import helpers.js cause its in a different location and i dont know the file path…

Well, let me say… could be done or cb or bananas but, accordingly with the lessons must be “done”… any word works.

passport.deserializeUser((id, done) => {
helper.findById(id, function (err, user) {
if (err) return done(err);
return done(null, user);
})
});
it’s ok with "user"

router.post(
“/login”,
passport.authenticate(“local”, { failureRedirect: “/login” }),
(req, res) => {
res.redirect("…/");
});
works well…

One question… I supposed that when login is ok “Guest” have to change to “user”… struggling with something like that…?

Struggling with almost everything in this project, this is really crap.
If anyone have it working, I would be thankful for he/her to share his gitHub repository.

1 Like