Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. ...
  2. exports.getUserById = async (req,res,next,id) => {
  3. const user = await User.findOne({_id: id});
  4. req.profile = user;
  5. const profileId = mongoose.Types.ObjectId(req.profile._id);
  6. if(profileId.equals(req.user._id)){
  7. req.isAuthUser = true;
  8. return next();
  9. }
  10. next();
  11. }
  12.  
  13. exports.deleteUser = async (req,res) => {
  14. const { userId } = req.params;
  15. if(!req.isAuthUser){
  16. res.status(400).json({message: "You are not authorized"})
  17. }else{
  18. const deleteUser = await User.findOneAndDelete({_id: userId})
  19. res.json(deleteUser);
  20. }
  21. }
  22.  
  23. exports.checkAuth = async (req,res,next) => {
  24. if(req.isAuthenticated()){
  25. return next()
  26. }
  27. res.redirect("/signin")
  28. }
  29.  
  30. exports.getUserCurrent = async (req,res) => {
  31. const user = await req.user;
  32. res.json(user)
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement