Update Fauna Messages Collection with Authors

Shadid Haque
InstructorShadid Haque
Share this video with your friends

Social Share Links

Send Tweet
Published 8 months ago
Updated 5 months ago

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.

egghead
egghead
~ just now

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