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
Noahh15mo 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
HugoOP15mo 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
Angelelz15mo 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
Noahh15mo ago
are you using pages or app router?
Angelelz
Angelelz15mo ago
The fact that he mentions "use client" smells like app router
Noahh
Noahh15mo ago
oh duh
Hugo
HugoOP15mo ago
I guess Its app router I donc have /src Wanna check my repo ?
Noahh
Noahh15mo ago
Might as well, my GitHub is @ngregrichardson
Hugo
HugoOP15mo 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
Noahh15mo 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