You need to put all the things for authorization and routes inside the mongo.connect() function.
Your routes should not be inside the passport.use(new LocalStrategy function.
First, move everything after line 51 up to after line 47, right after the deserializeUser.
Then, take the three routes that are currently in the LocalStrategy ("/", “/profile”, and “/login”) and move them after the LocalStrategy function.
Also, did you change db to mongo to avoid the error? The error “db is not defined” was because you were trying to access it out of the database connection. The variable db is local to that function so anything that needs access to that variable needs to be inside that function. So change mongo back to db once you have put things in their proper places and there shouldn’t be an error.
Keep in mind that you still need to change the title variable to “Home Page”, that is not correct in the example code at that link. Also, right now you have it as “Home page” with an lowercase “p”. That might make the tests fail, I don’t know.
Sorry to hear you’re still having trouble with this.
Right now your Glitch app is not loading for me at all. I don’t know if that’s a problem with your code, or Glitch. Probably Glitch because there are no errors or anything. So that might be what’s causing the tests to time out. Are you seeing any errors when loading the page or in the console?
When I was doing these challenges, it happened a few times that my code would be fine but the tests would time out and fail. After refreshing the challenge page and trying a few times they would eventually pass. Don’t know if that was a problem with FCC or Glitch. But maybe something like that is happening to you.
Here’s another thing you can try. This is required by newer versions of mongodb, v3 I think.
mongo.connect(process.env.DATABASE, (err, client) => { //change db to client
if (err) {
console.log("Database error: " + err);
} else {
console.log("Successful database connection");
var db = client.db('test'); //add this line - if 'test' is not the short URL for your database you will have to change it
//put all authorization stuff and routes here
}
});
I remember some time back that I was also having issues with certain lessons. I’m pretty sure that I’ve had a similar issue with this one specifically. I’m glad that you’ve gotten it to work! Keep up the fantastic work.