流星:CallLoginMethod找不到错误



我很难调用登录方法,它遵循

$ meteor list
Accounts-base 1.2.14 A user account system
Ecmascript 0.6.1 Compiler plugin that supports ES2015 + in all .js files
Meteor-base 1.0.4 Packages that every Meteor app needs
React 15.0.1 Everything you need to use React with Meteor.
Static-html 1.1.13 Defines static page content in .html files

/server/main.js

import { Accounts } from 'meteor/accounts-base'
Accounts.registerLoginHandler('simples', (ttt) => {
  console.log(ttt);
});

/client/main.js

autenticar(){
  Accounts.callLoginMethod({
    methodName: 'simples',
    methodArguments: [{ tipo : 'simples' }],
    validateResult: function (result) {
    console.log('result', result);
    },
    userCallback: function(error) {
      if (error) {
        console.log('error', error);
      }
    }
  })
}

调用Authenticar()时,我会收到此错误:

errorClass
  Details: undefined
  Error: 404
  ErrorType: "Meteor.Error"
  Message: "Method 'simples' not found [404]"
  Reason: "Method 'simples' not found"

错误在哪里?

我从未亲自使用过此API,但是从快速浏览流星内部,我看到了几个问题。

Accounts.registerLoginHandler仅在内置处理程序数组中添加一个附加处理程序,这些处理程序被称为默认流星登录过程的一部分。

如果您要插入其他处理程序中的现有过程,则应致电Accounts.callLoginMethod ,而无需methodName密钥。

使用methodName调用Accounts.callLoginMethod将完全绕过内置处理程序并用您的自定义方法替换它们,但是您需要用Meteor.methods而不是registerLoginHandler单独声明此方法。

因此,这可能是您的错误 - 您需要使用Meteor.methods定义simples方法。另外,您应该检查该方法要求的代码,请参阅此处的代码中的注释:

https://github.com/meteor/meteor/meteor/blob/devel/packages/accounts-base/accounts_client.js

仅是为了补充并作为其他人来到这里的转介。这样它正在工作

client.js

Accounts.callLoginMethod({
  methodArguments: [{tipo: 'simples'}],
  validateResult: (result) => {
    console.log('success', result);
  },
  userCallback: function(error) {
    if (error) {
      console.log('error', error);
    }
  }
});

server.js

Meteor.startup(function () {
  var config = Accounts.loginServiceConfiguration.findOne({
    service : 'simples'
  });
  if (!config) {
    Accounts.loginServiceConfiguration.insert({ service: 'simples' });
  }
});
Accounts.registerLoginHandler((opts) => {
  if(opts.tipo === 'simples'){
    return Accounts.updateOrCreateUserFromExternalService ('simples', {
      id: 0 // need define something
    }, {
      options : 'optional'
    })
  }
});

相关内容

最新更新