Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MeteorJs "loginWIthPassword" seems not to work in method

It seems that the "Meteor.loginWithPassword" function does not work when called in a method.

I want to create my login form with autoforms and so I created a callback method which get called after a user submitted the login form. The form gets called the right way but the loginWithPassword function does not seems to work.

This is my method (on Client & Server side)

Meteor.methods({
    autoform_test_login : function (doc) {
        console.log('Called login method');
        if (Meteor.isClient) {
            Meteor.loginWithPassword('test', 'test', function(e) {
                if (e) {
                    console.log(e);
                }
            });
        }
    }
});

My autoforms calls this method when submitting with:

{{#autoForm schema="Schema_Login" id="form_login" type="method" meteormethod="autoform_test_login"}}
....

When submitting this form I get this error:

 Error: No result from call to login {stack: (...), message: "No result from call to login"}

When I now open my Browser console and type in:

Meteor.call('autoform_test_login');

I will get the same error.

But: When I type the following in my console it works (The error now is: Username not found):

Meteor.loginWithPassword('test', 'test', function(e) {
                if (e) {
                    console.log(e);
                }
            });

My method do absolutely nothing else then this snipped so I am asking myself whats going wrong here.

Ps.: I know that I added the "test" as Username and "test" as password - its just to test. Even when the input is the right the error is always the same.

like image 234
TJR Avatar asked Jan 26 '15 20:01

TJR


1 Answers

Okay, so I got a response and now I know why this is not working as expected.

  1. loginWithPassord may only be executed on the client.
  2. When you use Meteor.methods on the client, it will still run the functions you define within it on the server. That is why it won't work to have the loginWithPassword call within a Meteor.methods function.
  3. Simply use this function anywhere else on the client. For example - directly within some template event.

Took me like forever to find out why it wasn't working.

like image 103
Patrick Hübl-Neschkudla Avatar answered Oct 07 '22 04:10

Patrick Hübl-Neschkudla