angularfire2

AngularFire2 - How to maintain logged in state after page refresh

百般思念 提交于 2020-01-12 09:51:45
问题 I'm using AngularFire2 for an app and I've gotten the registration/login functionality working with Firebase, however, every time I refresh the page, the logged in state is reset and won't persist. I can't quite find functionality to do this, though I feel I'm missing something very small. Can I use the AngularFireAuth to check on page load somewhere? Here is my auth provider code: import { Injectable } from '@angular/core'; import {Observable, Subject, BehaviorSubject} from "rxjs/Rx"; import

AngularFire 2 - Auth.logout() callback

泄露秘密 提交于 2020-01-11 10:15:07
问题 I'm trying to logout and then navigate to a login url, but the authguard from this url prevents logged users to view it and since the second line is reached before the promise is resolved you need to click the method event twice to make it work. logout(){ this.angularfire.auth.logout(); this.router.navigate(['']); } Is there a way to implement router.navigate inside a callback when the promise is resolved? I've tried then(), but either my syntax was incorrect or there is a problem with auth

Firestore, Angular, AngularFire2 - Adding document with a reference type field

谁都会走 提交于 2020-01-06 08:44:33
问题 Is there a way to add a document with a reference type field to a collection? 回答1: Oh ... I made a mistake ... it's simple - we get a reference DocumentReference type (like this.firestoreService.doc(ref).ref ) and store it in our object. 来源: https://stackoverflow.com/questions/49935811/firestore-angular-angularfire2-adding-document-with-a-reference-type-field

Retrieve a list with angularFire and more than one child

走远了吗. 提交于 2020-01-06 05:53:49
问题 I'm using angularFire to connect my page to my database. I want to display all the users stored in my firebase database in the form of a list on a page. The way I am storing these users is like this : users |_date1 | |_hour1 | |_email:name |_date2 | |_hour2 | |_email:name |... if I use the method below, I can only get one "subsection", not the other children... this.fireDB.list('users').snapshotChanges().subscribe(res => { res.forEach(doc => { this.credentialsArray.push(doc.key, doc.payload

Angularfire2: Proper approach to check if user is logged in?

丶灬走出姿态 提交于 2020-01-05 05:46:05
问题 I wan't to allow only logged in users to access a certain site. What's the proper way of checking if a user is logged in on load? The code below is my first try, don't really know if it works though. Of course I already wrote db rules, now I want to complete the behavior visually for the user. this.af.auth.subscribe(auth => { if (auth) { //route to other view } else { //do whatever } }); 回答1: You should consider use angular 2 guards, like canActivate. They can help you to do validation before

FireStore Querying for a single document

会有一股神秘感。 提交于 2020-01-05 03:59:12
问题 background: I am trying to retrieve one document from a collection with a value rather than it's ID. I'm basically trying to make a login system. I tried this solution: Firestore : Retrieve a single document using flat-map to and limit(1) to do it but it does not seem to give anything, this is what my code looks like right now: this.user = this.afs.collection('users/', ref => ref.where('username', '==', this.username).limit(1)).valueChanges().flatMap(result => result); console.log(this.user

Grabbing the current user in AngularFireAuth

情到浓时终转凉″ 提交于 2020-01-04 07:36:46
问题 How do I grab the logged in user? I am doing this: console.log('Logging in...'); this.afAuth.auth.signInWithEmailAndPassword(this.email, this.password); But the docs are not clear on how to get the user in code. They show a way in the template but I need to store the current user. 回答1: To get current user: let user = AngularFireAuth.auth.currentUser; // returns user object For some reason each page refresh causes currentUser to disappear and I store user id (UID) in local storage, so I am

AngularFire2 - nested FirebaseObjectObservable won't fire a nested Firebase call

这一生的挚爱 提交于 2020-01-04 06:39:39
问题 I've got a question about dealing with working with many-to-many relationships in Firebase. Basically, I'm trying to build a user profile object from multiple paths inside of my Firebase data. I've tried building a function that returns an observable and then updates the data in that observable as a nested observable grabs data from Firebase. The problem is that the nested observable doesn't ever get called, from what I can tell. I've been beating my head against this for hours without any

AngularFire2 - nested FirebaseObjectObservable won't fire a nested Firebase call

試著忘記壹切 提交于 2020-01-04 06:39:26
问题 I've got a question about dealing with working with many-to-many relationships in Firebase. Basically, I'm trying to build a user profile object from multiple paths inside of my Firebase data. I've tried building a function that returns an observable and then updates the data in that observable as a nested observable grabs data from Firebase. The problem is that the nested observable doesn't ever get called, from what I can tell. I've been beating my head against this for hours without any

AngularFire2 typings: “Property 'take' does not exist on type 'FirebaseObjectObservable<any>'”

喜欢而已 提交于 2020-01-04 01:14:06
问题 I've updated my ionic app from beta 11 to rc0. So it means I've switched from typescript 1.8 to 2. I've configured AngularFire2 according to this site Getting Started with Ionic 2 RC0, Firebase 3 + AngularFire 2 I had this line of code working: this.af.database.object(`comments/${commentId}`).take(1).subscribe({ data => console.log(data) }); But now getting this error error TS2339: Property 'take' does not exist on type 'FirebaseObjectObservable'. Any ideas on what's going on? How can I solve