#Data fetching pattern with a different backend?

20 messages · Page 1 of 1 (latest)

vague dust
#

why is it preferred to fetch data in server side? In case of page router docs mention to use route handlers which run in server and for app router the preferred way is in server components. The issue is I’m fetching data from a backend which will be handling auth to so i wont be able to cache these fetch calls.

floral laurelBOT
#

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

vocal hawk
#

@vague dust server components are technically what your api routes did in pages

#

The reason it's recommended is cause it's very easy to use

#

If you don't want to cache, you can opt out from it easily

vague dust
#

why is it preferred in both cases to fetch from server side tho? isnt it an extra layer when you already have a backend server which handles both auth and data?

vocal hawk
#

To do so on the client you can just use react.

#

Your api routes, are also on the server

vague dust
#

i tried normal react but i wanted some routing features of nextjs cuz of url rewrites and stuff

#

i have a plan tho but idk if its a good one. we are using sessions for auth so i could maybe verify the sessions by accessing db directly and then call the fetch for data with some cache args. is this a good practice tho?

#

in this case i get auth and also could cache data too without compromising auth.

vague dust
vocal hawk
#

You can use env vars

#

Dosent require client to do heavy frtching

#

Much faster

vague dust
#

one more question like would this put a lot of load on server side tho? if im fetching from next server?