Update Fauna Messages Collection with Authors

Shadid Haque
InstructorShadid Haque
Share this video with your friends

Social Share Links

Send Tweet

Now that we have user information available to us, we want to connect messages created to the users that are sending them. When we add read privileges to the User model, we can call User.identity() to get the user data we need to set for messages.

[00:00] Currently, when we create a message, it doesn't show us which user this message was sent from. So let's go ahead and fix that. So we're gonna go back to our roles dot FSL file. And here in the auth role, we're going to add privileges for user collection, and [00:20] we're going to give read privileges to user collection. And we're going to push the changes with Fauna schema push command. So we're gonna navigate to our message form component. And in the [00:39] create message query, we're going to write let user equals to query dot identity. This will give us the identity of the current user. And then we're gonna add a author for the message and set it to be the current user. We're [00:59] also going to add the author name. Next, we're gonna go to the room page component. And here, we're gonna look for the messages response, and we're going to update this map function to have [01:19] the author information. Next, we're gonna go to the message list component, and here we're gonna look for the JSX to render the messages. [01:39] And we're gonna include the author name in the JSX. So now it's gonna render the author name. Alright. So let's give our application a quick [01:59] test. So for these messages, the author information is not available, so that's why it's showing anonymous. Let's go ahead and create a new message, and you'll see that the author information is visible now.