我在meteor中有一段代码,它会在会话中添加一个客户对象。 我如何使它成为一个通用的代码,以便我可以调用它进行正常登录/ fb登录/推特等? 我正在使用angularjs2 / meteor
MeteorObservable.call('getCustomer', Meteor.user().emails[0].address).subscribe((cust: Cust) =>
{
Session.set('session_cust',cust);
this.router.navigate(['/profile']);
}, (error) =>
{
console.log('session cust error');
});
答案 0 :(得分:0)
您可以使用Tracker.autorun来监视用户登录,与路径无关:
Tracker.autorun(() => {
if ( Meteor.user() ){
... your code - will only run when the user logs in
}
});
答案 1 :(得分:0)
@Injectable()
@InjectUser('user')
export class CustLoginService
{
constructor(private router: Router) { }
handleLogin(): void
{
if (Meteor.userId())
{
MeteorObservable.call('getCustomer', Meteor.user().emails[0].address).subscribe((cust: Cust) =>
{
if (cust)
{
Session.set('session_cust', cust);
this.router.navigate(['/profile']);
}
else
{
console.log('Not a customer');
this.router.navigate(['/zone-list']);
}
}, (error) =>
{
console.log('session cust error');
});
}
else
{
console.log('no meteor user id');
}
}
}