Search code examples
meteoraccountmeteor-accounts

Meteor.. accounts- password-- Create account on client without login


I'm using accounts-password package - Meteor.

I code interface for admin.

Admin will create accounts for other user.

Accounts.createUser({
        email: "[email protected]", 
        password : "abc123", 
        profile: { name: register_name }
   });

But after this code executed, my application automatic login with account [email protected], wich i don't want it

Question

How to create accounts without automatic login?

I read accounts-password source but i dont know how to remove automatic login

I also tried to use Meteor.users.insert function but Accounts.setPassword didn't work..


Solution

  • This is a normal behavior using accounts package, to avoid messing with the source code use a Meteor.method/Meteor.call.

    This is a simple example,also you can use the default username filed and not a profile:{name:register_name}.

        if(Meteor.isServer){
            Meteor.methods({
              createUserFromAdmin:function(emai,password,username){
                Accounts.createUser({email:email,password:password,username:username})
          }
        })
       }else if(Meteor.isClient){
            Template.admin.events({
             'click #createAccount':function(){
               Meteor.call('createUserFromAdmin',email,password,username,function(err,result){
                  if(!err){
                     console.log("a new user just got created")
                    }else{
                      console.log("something goes wrong with the following error message " +err.reason )
                    }
                 })
               }
            })
           }
    

    With this you can create multiple accounts on the admin template, and keep the autologin behavior on the sign-up template (if you have one)