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?

2 Likes

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…?

2 Likes

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.

3 Likes

Glad to see I’m not the only one having issues.

Register endpoint appears to work, but login doesn’t change guest to username and logout throws a ‘Cannot Get /login’ error.

I’m moving on to the ecommerce REST API portfolio project to try to piece together how to implement authentication correctly, would greatly appreciate any advice on that if someone’s figured it out.

1 Like

This is mine but it’s not really working properly. If someone can point out what I’m doing wrong, I’ll be glad.

Here is working fine, after a few bumps I got things going.

@dyrits your app.js is missing the user on the app.get(“/”…

app.get(“/”, (req, res) => {
const user = req.user || “Guest”; // I got this wrong at first and was bumping my head on the wall
res.render(“home”, { user });
});

Also I put the sameSite: “none”, secure: true, inside the cookie object, not sure if it makes any difference but in my anotations it was like that.

I am getting Error: Unknown authentication strategy "local". I have gone back and reviewed the material and the documantation from the Passport folks but cannot see any coding errors. The route code is the same as the above, so I went back and changed the cb to done as you suggested (no effect.) The cannot GET message sound as though you have erased or changed the route.get(“/login”… that was originally just above the module.exports code at the bottom of the file.

I’m kinda disapointed with this lesson:S

I’m in the middle of back-end engineer path and so far Codecademy was doing great. But last 2 lessons was propably the hardest thing i have ever done. They expect me to get TONS of knowledge in single 7-step lesson and then they throw me to project with almost blank hints and no walkthrough video. I’m confused

That was first project that I skipped. It’s simply too hard for me and there is no help for those who struggle.
CA please fix this:) I love your site but that part needs to be improved.

any url I try to go after completing all the tasks and making sure that the code is correct, just says “unauthorized”. Not sure what to do from here

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.