Get database informations inside 'use client' component

Hello, i would like to display categories from my database in my 'use client" component, how can i do ? i don't understand why i have this error when calling database: Module not found: Can't resolve 'net'
11 Replies
Noahh
Noahh13mo ago
Be very careful connecting to your database from the clientside! If you're directly connecting to the database, it means that the complete connection info (including password) is easily accessible for anyone using it. You probably want to have something serverside (during rendering or through an API call) connect to the database to keep that information safe from the public. If you do want to proceed, can you provide a little more context as to your setup? Next.js, how you're setting up Drizzle, etc. An example repository would be helpful.
Hugo
Hugo13mo ago
Hi, I can add you to my repo if you want I'm using next If possible I would like to prevent using a fetch, next is pretty useful mixing client and server side so if I can get database informations from server and then pass to client I would love to learn how to do that
Angelelz
Angelelz13mo ago
In next, the new pattern is to have Server components do the back end call and pass the data to client components via props
Noahh
Noahh13mo ago
are you using pages or app router?
Angelelz
Angelelz13mo ago
The fact that he mentions "use client" smells like app router
Noahh
Noahh13mo ago
oh duh
Hugo
Hugo13mo ago
I guess Its app router I donc have /src Wanna check my repo ?
Noahh
Noahh13mo ago
Might as well, my GitHub is @ngregrichardson
Hugo
Hugo13mo ago
the code is inside streeteats/admin/app/dashboard/foodtrucks/create/page.tsx this is a client side component and i'm calling the "CreateStoreForm ' component admin/app/dashboard/components/createStoreForm.tsx and this is where i call a hook asking data to database ( line 102 const categories = getCategories;)
Noahh
Noahh13mo ago
Since this has turned into a Next.js question rather than a Drizzle question and since the repo isn't public, I'm gonna move this to DMs.
Want results from more Discord servers?
Add your server