freeCodeCamp/curriculum/challenges/english/06-information-security-and.../advanced-node-and-express/logging-a-user-out.english.md

1.9 KiB

id title challengeType
58965611f9fc0f352b528e6c Logging a User Out 2

Description

As a reminder, this project is being built upon the following starter project on Glitch, or cloned from GitHub. 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.
app.route('/logout')
  .get((req, res) => {
    req.logout();
    res.redirect('/');
});

You may have noticed that we're 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.

Instructions

Tests

tests:
  - text: Logout route
    testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /req.logout/gi, 'You should be call req.logout() in youre /logout route'); }, xhr => { throw new Error(xhr.statusText); })
  - text: Logout should redirect to the home page /
    testString: getUserInput => $.get(getUserInput('url')+ '/logout') .then(data => { assert.match(data, /Home page/gi, 'When a user logs out they should be redirected to the homepage'); }, xhr => { throw new Error(xhr.statusText); })

Challenge Seed

Solution

// solution required