I got a collection named Admins and I use Admins.findOne({userId: Meteor.userID})
to check if a user is an admin and it works fine if I do it when I use it in the meteor shell and when I call the method I have defined for it from the browser console, but when I do server-side permission checks with it the Admins collection appears to be empty (Admins._collection._docs._map
is empty. I have checked.). I don’t know why my method can’t access it if I perform it on the server side, but works fine when I call it form the chrome dev tools. My methods are:
updateArticle: (id, obj) ->
console.log Admins
console.log Meteor.userId()
Meteor.call 'hasBasicPermissions', (err,res) ->
console.log res
if res
Articles.update(id, obj)
else
Meteor.call('notAuthorisedError')
isEditor: ->
!!Editors.findOne {userId: Meteor.userId()}
isAdmin: ->
!!Admins.findOne {userId: Meteor.userId()}
hasBasicPermissions: ->
console.log(Meteor.userId())
console.log(Admins)
res = !!Admins.findOne({userId: "9fZmAnoJubaGDZH64"}) or !!Admins.findOne({userId: "9fZmAnoJubaGDZH64"})
console.log res
return res
notAuthorisedError : ->
throw new Meteor.Error("not-authorized");