如何在 Meteor 中进行 Google 登录

How to do Google Sign-In in Meteor

我尝试了各种教程和链接,了解如何获得 Google 登录以在 Meteor 中工作,但无济于事。我如何在我的登录页面上创建一个 google 登录按钮,重定向到我的用户仪表板——也许使用 iron:router(并在角落显示人名),并限制 google 仅向 .edu 帐户发送电子邮件?

作为页面管理员,我如何才能看到所有登录我网站的人的 emails/names?这是通过 Google Analytics 完成的吗?

  • 对于 Google 登录,我建议安装 accounts-entry 包并从浏览器配置它:

    安装最新的 meteor 版本

    meteor add joshowens:accounts-entry

    对于 0.9 之前的流星版本使用

    mrt add accounts-entry

  • 对于您的仪表板重定向review the documentation for that package on atmospherejs.com演示了如何配置您的仪表板路由:

    dashboardRoute: '/dashboard'

  • iron-router包是accounts-entry的依赖,所以也会安装

  • 通过启动 MongoDB shell(启动您的应用程序后)访问数据

    meteor mongo

  • 使用 MongoDB shell:

    查询帐户

    db.users.find()

  • 这不是通过 Google Analytics

  • 处理的

尝试添加 accounts-google 包。您需要使用应用程序 keysecret 配置 Google 登录。最简单的方法是同时添加 accounts-ui 包并使用 {{> loginButtons}} 它将在 Google 页面上显示有关要遵循的步骤的详细说明。它还会适当地保存您的应用程序密钥和秘密令牌。

完成此操作后,您就可以使用该方法了 Meteor.loginWithGoogle() 如文档中所述。它需要一个可选的选项数组和一个回调函数

例如

Meteor.loginWithGoogle({}, function(error){
     if(error)
         //Couldn't log in
     else
         Router.go('/dashboard');
})

祝你好运