#Server actions are for mutation, what can I use for fetching data?

9 messages · Page 1 of 1 (latest)

sage badger
#

In the nextJS docs it says server actions are basically for form submissions:

Server Actions are asynchronous functions that are executed on the server. They can be used in Server and Client Components to handle form submissions and data mutations in Next.js applications.

Though it can be used for fetching data. My question is if the docs dont say its for fetching, then what could I use to async fetch data on the server side?
Do I have to use an api route?

Use case: I have a supabase instance which needs admin rights to fetch some data async and so has to be done on the server.

tawdry veldtBOT
#

🔎 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)

neon comet
sage badger
#

client side? not when you need supabase admin access as you shouldnt expose your admin key

neon comet
# sage badger client side? not when you need supabase admin access as you shouldnt expose your...

nah, not clientside. If you need data clientside you normaly pass it from a server component to the client component and fetch it serverside. If you can't do that, you technically can use server actions. However there are some disadvantages with it. Fetching data clientside should be done via api routes and a clientside fetching library like react query or swr to have cache and other useful stuff

sage badger
#

yeah ok so i guess api endpoints is a the recommended way to go, and not server actions

neon comet
sage badger
#

alright thats for clarifying

tawdry veldtBOT
#
✅ Success!

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

Jump to answer

[Click here](#1260502089797206087 message)