0

我真正需要的是在用户使用谷歌服务登录时为 javascript 加载谷歌 apis 客户端库。如果用户使用密码或其他外部服务登录,则不会加载库。

这有可能吗?

谢谢。

4

2 回答 2

1

如果您想在用户登录后从外部 URL 加载库,您可以尝试这样的操作(将其放在客户端代码中的任何位置):

Tracker.autorun(function(c) {
  var user = Meteor.user();

  // replace this with the appropriate check for a google account
  if (user && user.profile && user.profile.isGoogle) {
    // stop the autorun now that the user is logged in
    c.stop();

    // load the api library
    $.ajax({
      url: '//url-to-fancy-google-api.google.com',
      dataType: 'script',
      cache: true
    });
  }
});
于 2014-09-15T06:29:33.630 回答
0

有可能,使用anti:modules包。首先将其添加到应用程序中:

meteor add anti:modules

然后在您的项目中创建/layers文件夹并将您的可选文件放在其子文件夹中:

/
  layers
    googleUser
      someFile.module.js
      anotherFile.module.js
      ...

然后在您的代码中创建一个全局模块:

theApp = Module('$global').as('myApp');

并在必要时加载它:

theApp.require('googleUser', function () {
  console.log('googleUser code loaded');
});
于 2014-09-15T06:30:35.003 回答