Get user from firebase

#1

hello,

The script is to put results in firestore and that is no problem. Only thing is that every user sees all inputted items. What can be the best way to only see what user a inserted(user a items) and not what user b insert?

My guess is to use login name or something. I have already an option to use google login with Firebase but how can I combine the firebase login to check with the item in Firestore?

//import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AngularFirestore } from 'angularfire2/firestore';
import firebase from 'firebase';


/*
  Generated class for the TodosProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class TodosProvider {

  constructor(public db: AngularFirestore) {
	  
	  console.log('Hello TodosProvider Provider');

 }
	
	 list() {

   return this.db.collection('/todos', ref => ref.orderBy('complete').orderBy('text')).valueChanges();

 }
	
	

 add(text) {

   const id = this.db.createId();



   return this.db.collection('todos').doc(id).set({

     id: id,
	   
     text: text,

     complete: false,

     createdAt: firebase.firestore.FieldValue.serverTimestamp(),

     updatedAt: firebase.firestore.FieldValue.serverTimestamp()

   });

 }



 complete(todo) {

   return this.db.collection('todos').doc(todo.id).update({

     complete: todo.complete,

     updatedAt: firebase.firestore.FieldValue.serverTimestamp()

   });

 }



 delete(todo) {

   return this.db.collection('todos').doc(todo.id).delete();

 }

}

#2

Hey @RenzoM78

Here’s how I would approach this:

I would create a collection of users and inside of each user document add the user’s TODOs as a sub-collection, so the end result would be something like this in the database:

/users
  /userId
    /name
    /email
    /etc
    /todos
      /todo1Id
        /todoInfoHere

Then you can fetch the user-specific to-dos in your application

#3

Thankyou @javebratt :slight_smile: I found this yesterday:

And that is sort of the same you say to do.

#4

Yeah, Jeff has many great videos on angular-firebase stuff.

#5

I understand the part of a collection bur what I dont understand is how do I get a user uid from the logged in user into firestore.

#6

You need to save it yourself, once you create a new user, add the user info to a users/ collection in Firestore

#7

I have this Angular tutorial off how to do this:

But I cant get this working into Ionic, is there also a tutorial for Ionic how to do this with users? and data?