authentication.js 838 B

12345678910111213141516171819202122232425262728293031
  1. Meteor.startup(() => {
  2. Authentication = {};
  3. Authentication.checkUserId = function (userId) {
  4. if (userId === undefined) {
  5. const error = new Meteor.Error('Unauthorized', 'Unauthorized');
  6. error.statusCode = 401;
  7. throw error;
  8. }
  9. const admin = Users.findOne({ _id: userId, isAdmin: true });
  10. if (admin === undefined) {
  11. const error = new Meteor.Error('Forbidden', 'Forbidden');
  12. error.statusCode = 403;
  13. throw error;
  14. }
  15. };
  16. // This will only check if the user is logged in.
  17. // The authorization checks for the user will have to be done inside each API endpoint
  18. Authentication.checkLoggedIn = function(userId) {
  19. if(userId === undefined) {
  20. const error = new Meteor.Error('Unauthorized', 'Unauthorized');
  21. error.statusCode = 401;
  22. throw error;
  23. }
  24. };
  25. });