1. 19
    Store the User's ID in the Task Documents That are Saved in Firestore
    2m 25s

Store the User's ID in the Task Documents That are Saved in Firestore

Jorge Vergara
InstructorJorge Vergara
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated a year ago

Now that we have users in our application, we need to start associating them with tasks that are created. We'll revisit our task object and add our currently logged-in user's ID to our task object so that we can show users only their tasks. This is done through the Firebase Auth module.

Man 1: [0:00] Now that our authentication system is in place, we are going to start preparing our application to make it more secure. We are going to make one change right now and it's that we are going to add the user ID to the task object.

[0:18] When a user creates a task, we're going to add a user ID property into that task so that we can differentiate which user created which task. For that we are going to start by importing off into our class from AngularFire [inaudible] and then we have to inject it into the constructor.

[0:43] Then we are going to navigate to our save task function and we are going to create a new variable that's going to be the user ID. Here, we are going to say this is going to be the current user.UID. If it's not there, we are going to say that the user ID is null.

[1:06] Then as a fail safe, we are going to say that if there is no user ID we are going to return our function and we are going to avoid doing all of the processing for the database. Then once we have our task we are going to say task.user equals the user ID. We have an error here because user doesn't exist on type task.

[1:37] We are going to go back to find our task model and we are going to add the user property. This means that we also have to add it here. Now, we are going to open one of our tasks and we see this one map out outflow and we are going to click on save task.

[1:58] We see task successfully updated so we are going to go into our console, we look for our task and we see map out outflow. We get this user ID, RSL. If we go to authentication, we see RSL like that's the user ID of this user.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today