Add User Data to a Post Creation in Remix

Ian Jones
InstructorIan Jones
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Finally, you want to associate users to the posts that they make. To do this you will grab the user data from authenticator.isAuthenticated API to pass to the post creation. This data does not need to be validated because it’s coming from the session storage which has already been validated.

Instructor: [0:00] Here in the Prisma schema, you can see that a post has an authorId. When you created the model, you added this feature, but you haven't been able to add users to the posts until authentication was completed.

[0:14] In the index action, you can see that a bad user ID is being passed. You only want authenticated users to be able to create posts. You can call authenticator.isAuthenticated inside of the action to accomplish this.

[0:31] This will protect the index route, as well as provide the authorId you need for the post. You don't need to validate this piece of data because it is provided by the session and not the user input.

[0:45] Next, you can pass user.id as the authorId when creating a post. Head on over to the browser and you can see, when you create a post, the user information is on it.

[1:05] To review, you pulled the user ID off of the call to authenticator.isAuthenticated. Then, you pass the user ID to the createPost function. You didn't have to validate this data because it is being provided by the session and not the user input.

egghead
egghead
~ 2 hours 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