【问题标题】:Cannot authenticate to mongodb stitch app with google oauth无法使用 google oauth 对 mongodb 缝合应用程序进行身份验证
【发布时间】:2018-08-21 04:37:35
【问题描述】:

我在 vue.js 前端工作。如果我使用匿名身份验证,我可以成功调用缝合并写入数据库。当我切换到 Google oauth 并尝试对数据库进行相同的写入调用时,我收到以下错误:

uncaught exception: t: (MustAuthenticateFirst): method called requires being authenticated

我已在 Stitch 管理控制台中设置了 Google 身份验证提供程序。我在 Google Cloud Platform 上创建并配置了一个项目。在我的 vue 代码中,我添加了一个运行此 sn-p 的“使用 google 登录”按钮:

  loginWithGoogle() {
    const googleCredential = new GoogleRedirectCredential();
    client.auth.loginWithRedirect(googleCredential);
  },

当我点击登录时,我被重定向到 Google 表单并被 Google 要求登录,然后成功重定向回我的应用程序。但是当我尝试写入拼接数据库时,它仍然说我必须先进行身份验证。

【问题讨论】:

    标签: vuejs2 google-oauth mongodb-stitch


    【解决方案1】:

    当 google 重定向回您的应用程序时,您是否调用 de hasRedirectResult() 和 handleRedirectResult()?此方法在本地存储凭据(我在本地存储中来宾)。

    【讨论】:

    • 完美。将这两个方法添加到由 vue created 生命周期挂钩调用的方法中,一切都按预期工作。
    猜你喜欢
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 2018-06-27
    相关资源
    最近更新 更多