MeteorJs “loginWIthPassword” seems not to work in method

自作多情 提交于 2019-12-10 04:44:08

问题


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.


回答1:


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.




回答2:


Make sure that autoform is actually passing the correct values. If you've made a mistake in you're schema setup it will automatically clean the values (set to undefined) without throwing an error.

I'm also not entirely sure if using it with method set will work in this case, as you want to do the login call on the client not the server (I think).




回答3:


Make sure your current Meteor instance has an active connection with the mongo database pointed to by variable MONGO_URL. Meteor.loginWithPassword fails to give error feedback when this connection gets closed or broken.



来源:https://stackoverflow.com/questions/28157945/meteorjs-loginwithpassword-seems-not-to-work-in-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!