#Tutorial guy importing server component inside a client component, how is it safe?

23 messages · Page 1 of 1 (latest)

willow ploverBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

rough elk
#

As you can see, he's importing this addTodo component into a client component, and inside this addTodo, he's creating entries in the database, is this safe?

crimson drift
# rough elk As you can see, he's importing this addTodo component into a client component, a...

yes it is safe, because the function will be executed serverside as you can see on the directive on top use server: (see attached). Like that this function will be executed serverside. But keep in mind, that everything that is passed to that function newTodo (in this case) is controlled by the client. So you might want to validate it before using it in sql statements to avoid sql injections

rough elk
#

I'm validating inside this script with zod

crimson drift
crimson drift
rough elk
rough elk
#

And my last question, can I use NextRequest inside this addTodo function? I want to get the current url of the page somehow

crimson drift
crimson drift
rough elk
crimson drift
rough elk
crimson drift
rough elk
#

I will when I get back to my pc

willow ploverBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer
zinc jungle
#

for archival purposes, please do not delete the original question. if you want to get rid of it in the channel list, simply unfollow it.

rough elk
#

Sorry, it was a missclick