Search code examples
meteormeteor-accounts

Meteor.loginWithPassword restrict to admin only


I am looking for a handler that enables me to add a further check on the server side for the meteor account package when calling Meteor.loginWithPassword.

I am using roles and want to restrict login to admin. I have looked at the documentation and can't find anything.

I know I can check on the client side but would prefer this to be done on the server. Is this possible? I know you can do it when you create a user using Accounts.onCreateUser.


Solution

  • Try validateLoginAttempt method

    Accounts.validateLoginAttempt(function(attempt){
      //userId is available at "attempt.user._id"
    
     //check admin or not, return false to abort login
    
    });