在下面的非angularfire伪代码中,我希望firebase生成一个用于推送新数据的密钥.
var ref = Firebase(...);
var newref = ref.push({"blah":"blah"});
var autoKey = newref.name();
Run Code Online (Sandbox Code Playgroud)
我尝试通过angularfire与绑定模型做同样的事情,但它只是给我错误的对象没有push()方法,类似于这个问题.当数据类型是数组时,他让它工作.
如何获得我在常规Firebase(非angularFire)中使用对象自动键看到的漂亮行为?
我创建了一个像这样的用户数组 -
var ref = new Firebase(FIREBASE_URL + '/users');
var users = $firebaseArray(ref);
Run Code Online (Sandbox Code Playgroud)
我已经添加了对象,我想循环遍历此数组中的每个用户.我知道在使用ng-repeat的视图中这是可能的,但我需要在控制器中执行此操作.我试过了 -
angular.forEach(users, function(user) {
console.log(user);
})
Run Code Online (Sandbox Code Playgroud)
但是我没有得到这个结果.
因此,每当我从Firebase注销时,我都会加入
Error: permission_denied: Client doesn't have permission to access the desired data.
Run Code Online (Sandbox Code Playgroud)
我理解这是因为登录会话终止,我的一些对象无法再访问firebase数据.但是如何在注销前断开此对象?
对于我的Ionic View中的注销按钮,它只需调用firebase服务:
function logout() {
auth.$unauth();
getCurrentUser();
};
function getCurrentUser() {
var authData = auth.$getAuth();
if (authData) {
$rootScope.userId = authData.uid;
$rootScope.currentUser = $firebaseObject(authRef.child("users").child(authData.uid));
return $rootScope.currentUser;
} else {
console.log("User is not login!");
$rootScope.userId = null;
$location.path("/auth/signin");
if ($rootScope.currentUser) {
$rootScope.currentUser.$destroy();
}
}
};
Run Code Online (Sandbox Code Playgroud)
所以我在那里销毁$ rootScope.currentUser.我为配置文件页面使用相同的getCurrentUser.因此错误没有以这种方式出现.但是在其他视图中,我有另一个$ firebaseArray,还有另一个Ref.on("child_added",函数(snap)与$ firebaseObject相同.当我查看配置文件页面时,此页面至少有3个firebase连接,当我退出时,我有3个permission_denied错误(注销按钮在用户个人资料页面上).
我的问题是,在注销之前如何断开此firebase连接?有没有办法断开所有firebase连接 - 无论是AngularFire还是常规的Firebase?所以我可以注销而不用担心哪个firebase连接没有关闭呢?此外,由于Logout按钮位于Profile范围内,而其他连接位于不同的范围内,因此我不知道如何关闭甚至在配置文件范围内的连接...
我目前正在使用Firebase和AngularFire构建一个Angular 1.x应用程序作为我的后端/服务器.由于应用程序/网站针对移动设备进行了优化,并且在将其添加到主页时非常适合作为应用程序使用,因此我想知道即使手机处于脱机状态,如何让用户使用它.
在网上搜索,我发现Firebase为Android Java的对应物提供了keepSynced(true),但是我无法为js找到这样的选项.然后,我使用HTML5的localStorage和基于上次更改时间的同步进行手动方法,但由于我使用了一些AngularFire的方便命令(例如$ save),我的大部分代码都被破坏了.
有什么建议吗?
登录后,我订阅了一些firebase引用,然后注销(FirebaseAuth.logout).一旦我注销,我在控制台中收到Firebase警告:"用户回调抛出了异常.错误:允许在...处的许可",这成为一个实际的异常.虽然我确实希望看到这种行为,但是记录用户的最佳做法是什么,所以我没有看到这个警告/异常?
当我在home.ts中创建Ionic 2 app导入两个文件时,FirebaseListObservable和Angularfire没有导出成员"angularfire2"
我的Cordova和离子版本是Cordova版本6.5.0离子版本2.2.3节点版本6.10.2类型版本2.1.1打字稿版本2.3.2
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {AngularFire, FirebaseListObservable} from 'angularfire2';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, af:AngularFire ) {
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将ngx-admin与firebase集成.我已经在我的角度项目中安装了firebase.但是它给了我这样的错误"typescript错误无法找到模块'firebase/app'." 我也试着安装打字,但没有运气
我的stackstrace
D:\admin-ionic> ng serve
Your global Angular CLI version (1.6.1) is greater than your local
version (1.4.9). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-12-21T08:36:34.546Z
Hash: ecdd99ad138ea0774dff
Time: 8026ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 1.06 kB {vendor} [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) …Run Code Online (Sandbox Code Playgroud) 这是关于npm包'hoek'中的原型污染安全漏洞,它是firebase@3.xx的子依赖
Hackone Url:https://hackerone.com/reports/310439
Snyk Url:https://snyk.io/test/npm/firebase/3.9.0 ? sever = high & sever = medium & severity = low
虽然firebase团队已将其修复为此版本:https://github.com/firebase/firebase-js-sdk/issues/515 in package firebase@4.xx
我想了解这是否真的是对firebase的安全威胁,因为依赖于firebase@3.xx的人不能直接升级到@ 4.xx,因为它是一个重大变化,特别是如果他们使用angularfire@2.xx它不支持firebase @ 4.公开问题:https://github.com/firebase/angularfire/issues/934
根据上述hackone网址,该问题的影响是:
这表明攻击者可以向服务器上的所有现有对象添加属性.通过替换"toString"或"valueOf",可以使用附加属性来更改执行代码流或在每个后续请求中导致错误.
保证此漏洞至少获得拒绝服务,因为所有库都允许将属性"toString"和"valueOf"替换为"String".这会破坏express模块并强制服务器崩溃或向每个后续请求返回500.
可以制作更复杂的有效负载以获得远程代码执行(参见#309391中的PoC).
从阅读本文中我了解到,直接/间接使用hoek软件包的应用程序只有在服务器上运行时才容易受到攻击.
因此,使用使用firebase@3.xx的angularfire@2.xx的应用程序仅提供给客户端而不是在服务器上运行.
它仍然脆弱吗?
我正在构建一个 Angular WEB应用程序,它具有 Firebase 的云推送通知功能。我使用 AngularFireMessaging 服务(来自 Angular Fire 库)。首先,当应用程序启动时,我会检查用户是否已经授予权限并请求令牌,这可以使用 getToken() 方法轻松完成。这是我正在做的一个非常简短的例子:
import { AngularFireMessaging } from '@angular/fire/messaging';
@Injectable()
export class PushNotificationsService {
constructor(private afMessaging: AngularFireMessaging) {}
detectPermissionStatus(): Observable<string> {
return this.afMessaging.getToken().pipe(
map(token => { /*.... some code here....*/ })
);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我已经授予权限并且令牌可用,则可观察对象会立即返回它,然后我会做任何我想做的事情。但是,如果我没有任何权限状态(例如,当我第一次访问该页面时),则会调用默认浏览器提示以允许/拒绝通知。这对我来说似乎很奇怪,因为我没有明确调用 requestPermission() 函数。似乎 getToken() 函数也以某种方式使浏览器调用提示。这是我并不真正想要的行为,因为它会阻止我的应用程序继续运行,因为我依赖于要返回的某些东西(无论它是现有令牌还是什么都没有)才能继续处理我需要的其余请求去做。
所以......简短的问题 - 有没有办法检查用户是否已经请求令牌而不调用提示?
编辑: 如果您想知道为什么我需要以这种方式执行这些操作 - 这是因为我想在发送登录请求之前检查用户是否有令牌以及是否存在令牌 - 我将令牌与登录一起发送要求。然后在后端,我只是检查该用户是否已经与此令牌相关联(使用同一浏览器的多个用户共享一个令牌可能会发生这种情况),如果是 - 他们对此订阅的最新决定是什么(他们是否选择了不在通知中)。我希望你已经明白了 - 如果出现提示窗口,应用程序只是挂起并等待做出某些决定,然后我们继续登录。
编辑: 我发现的另一个解决方案是使用内置于 Notification api 的浏览器。使用 Notification.permission 我可以看到权限的状态(默认、拒绝或授予)。如果它返回状态“已授予”,我知道我有一个令牌,我可以继续从 firebase 消息传递调用 getToken()。否则,我会直接跳到登录,稍后当用户决定订阅通知时,我将调用提示。
permissions token angularfire firebase-cloud-messaging angular
我正在使用Ionic & Angular & Angular Fire & Firebase。我已经成功连接到Firestore 数据库,并且能够操作数据。
\n Ionic CLI : 6.18.1\n Ionic Framework : @ionic/angular 6.0.11\n @angular-devkit/build-angular : 13.2.6\n @angular-devkit/schematics : 13.2.6\n @angular/cli : 13.2.6\n @ionic/angular-toolkit : 6.1.0\n @angular/angularfire : 7.2.1 \nRun Code Online (Sandbox Code Playgroud)\n应用程序模块.ts
\nimport { environment } from \'../environments/environment\';\nimport { initializeApp, provideFirebaseApp } from \'@angular/fire/app\';\nimport { provideAuth, getAuth } from \'@angular/fire/auth\';\nimport { provideFirestore, getFirestore } from \'@angular/fire/firestore\';\n\n@NgModule({\n ...\n imports: [\n ...\n provideFirebaseApp(\n () …Run Code Online (Sandbox Code Playgroud)