Now we need to allow a new user on our site to register an account. On the <code>res.render</code> for the home page add a new variable to the object passed along--<code>showRegistration: true</code>. When you refresh your page, you should then see the registration form that was already created in your <code>index.pug</code> file! This form is set up to <b>POST</b> on <code>/register</code>, so this is where we should set up to accept the <b>POST</b> and create the user object in the database.
The logic of step 1, registering the new user, should be as follows: Query database with a findOne command > if user is returned then it exists and redirect back to home <em>OR</em> if user is undefined and no error occurs then 'insertOne' into the database with the username and password, and, as long as no errors occur, call <em>next</em> to go to step 2, authenticating the new user, which we've already written the logic for in our POST <em>/login</em> route.
Submit your page when you think you've got it right. If you're running into errors, you can check out the project completed up to this point <ahref='https://gist.github.com/camperbot/b230a5b3bbc89b1fa0ce32a2aa7b083e'target='_blank'>here</a>.
**NOTE:** From this point onwards, issues can arise relating to the use of the _picture-in-picture_ browser. If you are using an online IDE which offers a preview of the app within the editor, it is recommended to open this preview in a new tab.
testString: "getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /showRegistration:( |)true/gi, 'You should be passing the variable showRegistration as true to your render function for the homepage'); 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); })"
testString: "getUserInput => $.ajax({url: getUserInput('url')+ '/profile', type: 'GET', crossDomain: true, xhrFields: { withCredentials: true }}) .then(data => { assert.match(data, /Home/gi, 'Profile should redirect to home when we are logged out now again'); }, xhr => { throw new Error(xhr.statusText); })"