I was following this tutorial by @Dennis Ivy . One thing I didn't understand was why we are creating a new session using createSessionClient
before fetching the documents. Why can't we directly fetch it like this:
const { documents: orders, total } = await databases.listDocuments(
process.env.NEXT_PUBLIC_DATABASE_ID,
process.env.NEXT_PUBLIC_COLLECTION_ORDERS
);
Second question I have is why we are creating an API route to fetch the data from Appwrite DB when we can directly fetch it from the server component to avoid an extra API call? (That's one of the benefits of using a server component.)
Tutorial Link: https://www.youtube.com/watch?v=ENnG7GusuO4 Source Code: https://github.com/divanov11/Nextjs-Appwrite-Auth-SSR/blob/main/src/app/api/orders/route.js
Any help is appreciated!
How to fetch and create documents while using Server Component in NextJs?
Recommended threads
- Got message for auto payment of 15usd fo...
how did this happen? 1. i claimed my 50usd credits via jsm hackathon - https://hackathon.jsmastery.pro/ 2. it asked me which org. to apply the credits on, i se...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- Error: User (role: guests) missing scope...
I want to send a verification code to the user and the given phone number and check it and create a session right after the user entered the secret. For me that...