"Register route and display on home" is not passing

Tell us what’s happening:

“Register route and display on home” is not passing (all others are)

I’ve ready through the various support articles and a bunch of them mention changing the title and the h1 header on the index.pug and profile.pug files, and I’ve tried various combinations, but can’t seem to get it to work

Your code so far

Here is a link to my actual glitch. Below is the relevant portions of code.

In addition to what’s below, I’ve tried changing the h1 in the index.pug to Home Page and tried adding freeCodeCampTester to the end of the h1 in the index and one person suggested…none of those passed.

index.pug:

html
  head
    title Home Page
    meta(name='description', content='A cool thing made with HyperDev')
    link#favicon(rel='icon', href='https://hyperdev.com/favicon-app.ico', type='image/x-icon')
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width, initial-scale=1')
    link(rel='stylesheet', href='/public/style.css')
  body
    h1.border.center FCC Advanced Node and Express
    h2.center#pug-success-message
    | Looks like this page is being rendered from Pug into HTML!
    | #{title}
    p#pug-variable= message

profile.pug:

html
  head
    title Profile Page
    meta(name='description', content='Profile')
    link#favicon(rel='icon', href='https://hyperdev.com/favicon-app.ico', type='image/x-icon')
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width, initial-scale=1')
    link(rel='stylesheet', href='/public/style.css')
  body
    h1.border.center Profile Page
    //add your code below, make sure its indented at this level
    h2.center#welcome Welcome, #{username}!
        a(href='/logout') Logout
    script(src='https://code.jquery.com/jquery-2.2.1.min.js', integrity='sha256-gvQgAFzTH6trSrAWoH1iPo9Xc96QxSZ3feW6kem+O00=', crossorigin='anonymous')
    script(src='/public/client.js')

server:

 app.route('/')
  .get((req, res) => {
    res.render(process.cwd() + '/views/pug/index.pug', {title: 'Home Page', message: 'Please login', showLogin: true, showRegistration: true});
  });
  
  app.post('/login', passport.authenticate('local', {failureRedirect: '/'}), function(req, res){
    res.redirect('/profile');
  });
  
  app.get('/profile', ensureAuthenticated, function(req, res){
    res.render(process.cwd() + '/views/pug/profile.pug', {username: req.user.username})
  });
  
  app.get('/logout', function(req, res){
    req.logout();
    res.redirect('/');
  });
  
  app.post('/register', function(req, res, next){
    db.collection('users').findOne({username: req.body.username}, function(err, user){
      if (err) return next(err);
      if (user) return res.redirect('/');
      db.collection('users').insertOne({
        username: req.body.username,
        password: req.body.password
      }, function(err, doc){
        if (err) return res.redirect('/');
        next(null, user);
      });
    });
  }, passport.authenticate('local', {failureRedirect: '/'}), function(req, res){
    res.redirect('/profile');
  });

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36.

Challenge: undefined

Link to the challenge:
https://www.freecodecamp.org/learn/information-security-and-quality-assurance/advanced-node-and-express/registration-of-new-users

I figured this out…for anyone that is running into the same issue. The assert that was failing was this:

assert.match(data, /register[^]*post[^]*findOne[^]*username:( |)req.body.username/gi, ''You should have a route accepted a post request on register that querys the db with findone and the query being "username: req.body.username"''); }, xhr => { throw new Error(xhr.statusText); })'

Because I was using app.post('/register'... but the assert requires '/register' to occur before post so the format needs to be app.route('/register').post(function...)

4 Likes