Skip to main content

--description--

Creating the logout logic is easy. The route should just unauthenticate the user, and redirect to the home page instead of rendering any view.

In passport, unauthenticating a user is as easy as just calling req.logout() before redirecting. Add this /logout route to do that:

app.route('/logout')
.get((req, res) => {
req.logout();
res.redirect('/');
});

You may have noticed that you are not handling missing pages (404). The common way to handle this in Node is with the following middleware. Go ahead and add this in after all your other routes:

app.use((req, res, next) => {
res.status(404)
.type('text')
.send('Not Found');
});

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.

--hints--

req.logout() should be called in your /logout route.

async (getUserInput) => {
const url = new URL("/_api/server.js", getUserInput("url"));
const res = await fetch(url);
const data = await res.text();
assert.match(
data,
/req.logout/gi,
'You should be calling req.logout() in your /logout route'
);
}

/logout should redirect to the home page.

async (getUserInput) => {
const url = new URL("/logout", getUserInput("url"));
const res = await fetch(url);
const data = await res.text();
assert.match(
data,
/Home page/gi,
'When a user logs out they should be redirected to the homepage'
);
}