javascript - Polymer、Firebase 和 Google 登录, "Cannot read property push"

标签 javascript firebase polymer google-signin

我正在尝试完成 this tutorial但是当我尝试合并 Google 登录时,我不断收到“无法读取属性推送”错误。所以从看this answer好像我无法通过 Google 登录登录,所以我无法使用 Firebase 的“推送”。

我无法弄清楚是什么阻止了我登录。

我按照说明中的步骤操作

1.) 创建一个新项目

2.) 创建 OAuth 客户端 ID 凭证

3.) 创建同意屏幕 4.) 为应用类型选择的网络应用

5.) 按照指示授权 JS 来源和重定向 URI

6.) 转到身份验证部分(不再有登录和身份验证部分)并添加我的客户端 ID 和客户端 secret web sdk 配置(他们不再有 Google 客户端 ID 和 secret 部分)

7.) Main.js 已更新为使用“google”作为提供者

每当我尝试使用该应用程序时,我都会收到“无法读取未定义的‘推送’属性”。教程中的代码是否不再有效?我已经从 github 页面复制代码并将 firebaseURL 替换为我的,所以我不确定还有什么问题。

任何帮助将不胜感激,谢谢!

按照要求

(function(document) {
  'use strict';

  var app = document.querySelector('#app');
  app.firebaseURL = "https://***my project here***.firebaseio.com";
  app.firebaseProvider = 'google';

  app.items = [];

  app.updateItems = function(snapshot) {
    this.items = [];
    snapshot.forEach(function(childSnapshot) {
      var item = childSnapshot.val();
      item.uid = childSnapshot.key();
      this.push('items', item);
    }.bind(this));
  };

  app.addItem = function(event) {
    event.preventDefault(); // Don't send the form!
    this.ref.push({
      done: false,
      text: app.newItemValue
    });
    app.newItemValue = '';
  };

  app.toggleItem = function(event) {
    this.ref.child(event.model.item.uid).update({done: event.model.item.done});
  };

  app.deleteItem = function(event) {
    this.ref.child(event.model.item.uid).remove();
  };

  app.onFirebaseError = function(e) {
    this.$.errorToast.text = e.detail.message;
    this.$.errorToast.show();
  };
  app.onFirebaseLogin = function(e) {
    this.ref = new Firebase(this.firebaseURL + '/user/' + e.detail.user.uid);
    this.ref.on('value', function(snapshot) {
      app.updateItems(snapshot);
    });
  };

})(document);

最佳答案

虽然我不确定确切原因是什么,但我可以告诉您,您正在学习的教程已经过时并且使用的是已弃用的 <firebase-element> (仅适用于 Firebase 2.0)。 element's GitHub page 上也说明了这一点:

Note: This element is for the older Firebase 2.0 API.

For the latest official Firebase 3.0-compatible component from the Firebase team, see the polymerfire component.

使用最新 polymerfire 的最新教程在:Build a Progressive Web App with Firebase, Polymerfire and Polymer Components

关于javascript - Polymer、Firebase 和 Google 登录, "Cannot read property push",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41770936/

相关文章:

javascript - 如何更新表单中表示的 JSON 对象

javascript - 使用页面操作在特定页面上显示 Chrome 扩展程序

javascript - firebase firestore 和 grpc 中未建立连接错误

firebase - 如何将 Apollo Server 2 与 Firebase 功能结合使用

javascript - 如何在 Polymer 中设置 url 变化的观察者?

javascript - 使用 SvelteKit 回退图像

javascript - TypeScript 无法缩小类型

javascript - 页面加载后仅获取新的 "child added"

html - polymer 预载微调器

javascript - 使用 Polymer.dom(this.root).querySelector 无法在 Polymer 元素中找到复选框元素