MeteorJs "loginWIthPassword" doesn't seem to work in the method

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

I want to create my autoform login form, and so I created a callback method that is called after the user has submitted the registration form. The form is called valid, but the loginWithPassword function does not work.

This is my method (client and 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 call this method when submitted 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 open the browser console now and type:

 Meteor.call('autoform_test_login'); 

I get the same error.

But: When I type the following in my console, it works (Error now: Username not found):

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

My method does absolutely nothing, moreover, it breaks off, so I ask myself what is going wrong here.

Ps .: I know that I added "test" as Username and "test" as a password - itโ€™s easy to verify it. Even when the input is correct, the error is always the same.

+5
source share
3 answers

Ok, so I got the answer, and now I know why this does not work as expected.

  • loginWithPassord can only be performed on the client.
  • When you use Meteor.methods on the client, it will still perform the functions that you define inside it on the server. This is why the loginWithPassword call inside the Meteor.methods function will not work.
  • Just use this function elsewhere on the client. For example, directly as part of a template event.

Took me forever to find out why it doesn't work.

+7
source

Make sure autoform is actually passing the correct values. If you make a mistake in setting up the scheme, it will automatically clear the values โ€‹โ€‹(set to undefined) without giving an error.

I'm also not quite sure if using this method will work in this case, since you want to make a login on the client and not on the server (I think).

0
source

Ensure that the current Meteor instance has an active connection to the mongo database that the MONGO_URL variable points to. Meteor.loginWithPassword does not give an error message when this connection closes or breaks.

0
source

Source: https://habr.com/ru/post/1211952/


All Articles