Browse Source

Step 11.10: Add extra security to methods.

Frederic G. MARAND 8 years ago
parent
commit
5fcc946853
1 changed files with 10 additions and 4 deletions
  1. 10 4
      simple-todos-react.jsx

+ 10 - 4
simple-todos-react.jsx

@@ -42,14 +42,20 @@ Meteor.methods({
   },
 
   removeTask(taskId) {
-    // Without checking user ?
-    Meteor._debug("removing", taskId);
+    const task = Tasks.find(taskId);
+    if (task.private && task.owner !== Meteor.userId) {
+      throw new Meteor.Error("not-authorized");
+    }
+
     Tasks.remove(taskId);
   },
 
   setChecked(taskId, setChecked) {
-    // Without checking user ?
-    Meteor._debug("setCheck", taskId, setChecked);
+    const task = Tasks.find(taskId);
+
+    if (task.private && task.owner != Meteor.userId) {
+      throw new Meteor.Error("not-authorized");
+    }
     Tasks.update(taskId, { $set: { checked: setChecked }});
   },