loading...

Day 35

mtee profile image Margaret W.N ・1 min read

I spent countless hours trying to implementing user permissions. It's still not making much sense. Authorization is complex and tutorials don't seem to be working out for me. Away from that i created an attribute: token where I'll save the token in the database. I also added a middleware to find users by id before performing the get, update and delete functions. Probably the only code that was working today.
Code in user controllers

const findUser = (req, res, next) => {
  User.findById(req.params.userId, (err, user) => {
    if (err) {
      return res.send(err);
    }
    if (user) {
      req.user = user;
      return next();
    }
    return res.sendStatus(404);
  })
};

Code in user routes

router.use('/users/:userId', userController.findUser);

We live to try another day.
Day 35

Discussion

pic
Editor guide
 

😅😅, Yes you will, and with the speed your learning with, it will be sooner that you expect, you'll see it's not as complex and your imagining right now.