I am using Meteor and React for my app. in my app, i use account-ui, account-facebook to let user is able to sign in by using facebook account. Now, i want to check if user is using facebook to sign-in Or regular user/pass to sign-in. I look at users collection and see that
1) if user used facebook to login, there is services.facebook in user collection
2) if user used regular user/pass to login, there is services.password in users collection
in server, i have method to return loginservice (facebook or password)
Meteor.methods({
getLoginService: function(){
let services = Meteor.user().services;
if (typeof services.facebook!=='undefined'){
return 'facebook';
}else if (typeof services.password!=='undefined'){
return 'password';
}
return 'undefined';
},
});
In client side, if will check to see if that is (facebook login) Or (User/pass login), then i can render the screen accordingly
App.Components.Dashboard = React.createClass({
render() {
var lservice='';
Meteor.call("getLoginService",function(error,service) {
if (error){
}else {
lservice = service;
}
});
if (lservice === 'facebook'){
return (
<div id="dashboard-content">
<div className="row">
<div className="col-lg-12">
<h1 className="page-header">Facebook connect</h1>
<p>put facebook information here</p>
</div>
</div>
</div>
);
}else{
return (
<div id="dashboard-content">
<div className="row">
<div className="col-lg-12">
<h1 className="page-header">Facebook connect</h1>
<p>put facebook connect button here</p>
</div>
</div>
</div>
);
}
}
});
The problem is at client side. Because Meteor.call is async so that lservice will not get the value from callback function. I also try to find a way to put html return into callback function(error, service) but not successful.
Do you know anyway to solve this problem. Or do you have any better idea to recognize what service that user used to login (maybe a hook to account-facebook)