2016-11-27 54 views
0
我有困難調用登錄方法

,它遵循流星: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" 

錯誤在哪裏?

回答

2

我從來沒有親自使用過這個API,但是通過流星內部的快速瀏覽,我發現了一些問題。

​​僅向內置處理程序數組添加了附加處理程序,該處理程序作爲默認Meteor登錄過程的一部分被調用。

如果你想在一個額外的處理程序插入到現有的過程中,你應該叫Accounts.callLoginMethod沒有methodName關鍵。

調用Accounts.callLoginMethodmethodName將完全繞過內置的處理程序,並與您的自定義的方法替換它們,但是這種方法需要單獨由你Meteor.methods,不registerLoginHandler聲明。

所以,這可能是你的錯誤 - 你需要用Meteor.methods定義你的simples方法。此外,你應該檢查該方法的要求的代碼,看到這裏的代碼中的註釋:

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

1

只有以補充和保持爲別人到這裏轉介。這樣,它的工作

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' 
    }) 
    } 
});