# Get user from firebase

**URL:** <https://forum.ionicframework.com/t/get-user-from-firebase/137524>\
**Category:** Ionic Framework\
**Created:** [August 6, 2018, 2:43pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524 "2018-08-06T14:43:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [August 6, 2018, 2:43pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/1 "2018-08-06T14:43:40Z")

</div>

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?

```auto
//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();

 }

}

```

---

<div class="post-metadata">

**Author:** ![javebratt](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/javebratt/32/104226_2.png) [@javebratt](https://forum.ionicframework.com/u/javebratt)\
**Post date:** [August 9, 2018, 12:36am UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/2 "2018-08-09T00:36:12Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [August 9, 2018, 6:14am UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/3 "2018-08-09T06:14:44Z")

</div>

Thankyou @javebratt 🙂 I found this yesterday:

> **[Associate Firebase Users to Database Records](https://angularfirebase.com/lessons/managing-firebase-user-relationships-to-database-records/)**
>
> Learn several different ways to associate database records with users who authenticated via Firebase

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

---

<div class="post-metadata">

**Author:** ![javebratt](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/javebratt/32/104226_2.png) [@javebratt](https://forum.ionicframework.com/u/javebratt)\
**Post date:** [August 9, 2018, 10:40pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/4 "2018-08-09T22:40:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [August 10, 2018, 7:08pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/5 "2018-08-10T19:08:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![javebratt](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/javebratt/32/104226_2.png) [@javebratt](https://forum.ionicframework.com/u/javebratt)\
**Post date:** [August 10, 2018, 11:03pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/6 "2018-08-10T23:03:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RenzoM78](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/renzom78/32/124246_2.png) [@RenzoM78](https://forum.ionicframework.com/u/RenzoM78)\
**Post date:** [August 15, 2018, 11:32am UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/7 "2018-08-15T11:32:40Z")

</div>

I have this Angular tutorial off how to do this:

> **[Firebase OAuth Login With Custom Firestore User Data](https://angularfirebase.com/lessons/google-user-auth-with-firestore-custom-data/)**
>
> Learn how to save custom user data in Firestore after authenticating with Google OAuth

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

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:26pm UTC](https://forum.ionicframework.com/t/get-user-from-firebase/137524/8 "2021-07-19T21:26:04Z")

</div>

Closed on July 19, 2021, 9:26pm UTC


