Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Juliana Miranda
Juliana Miranda
22,510 Points

I am trying to set an admin user in a node/express/mongodb app. Is this approach secure (and correct)?

// (...) async function to load profile page

function(error, results) {

  var user = results.user;
  var posts = results.user_posts;
  var admin_id = '5b0d6d1555713b1697ab647f';

  if (error) {
    return next(error);
  } else if (req.session.userId === admin_id) {
    res.send('You are the admin user.');
  } else if (req.session.userId === user.id){
    res.send('You are a regular user.');
  } else {
    res.send("Somebody else's profile.");
  }
 });