Back

[SOLVED] Can I use appwrite sdk using nextjs server components?

  • 0
  • General
  • Web
fafa
13 Nov, 2023, 16:29

Heyo,

The web-sdk is client based, I think. Is there an sdk that supports server components?

TL;DR
The user asked if they can use the Appwrite SDK with Next.js server components. Some advice was given to avoid using server-side components and to only fetch documents client-side. However, the user wanted to know if there is an example of using authentication and getting a cookie instead of local storage. The problem of 'Module not found: Can't resolve 'os'' was encountered, and the user mentioned trying the Rest API instead. A solution was suggested to use the web SDK and manually manage the session. Another user clarified that the web SDK is client-based and there is no SDK specifically for server components.
Kenny
13 Nov, 2023, 16:33
fafa
13 Nov, 2023, 16:34

If I try to use this, i get: ⨯ ./node_modules/node-appwrite/lib/client.js:1:11 Module not found: Can't resolve 'os'

fafa
13 Nov, 2023, 16:50

It seems to be the only way is to use the Rest API? I don't find any info about using it in server components, and installing fs etc. won't work.

Drake
13 Nov, 2023, 16:58

honestly, i would advise against using all the server-side related stuff, especially because you're going to run into problems with authentication and sessions.

You may be able to use the web SDK, but you would need to manually manage the session.

Module not found: Can't resolve 'os'

Ya....NextJS has multiple runtimes so the code may not actually be running in a node runtime 😑

fafa
13 Nov, 2023, 16:59

Hey, I understand with authentication etc. But what about getting documents? Or would you rather use api routes for this?

Drake
13 Nov, 2023, 17:00

I would try to avoid connecting to Appwrite server-side. I would only fetch the documents client-side.

fafa
13 Nov, 2023, 17:00

I do have one more question, is there a proper example on how to use authentication and get a cookie instead of local storage?

fafa
13 Nov, 2023, 17:01

Every time i login, I get it as local storage, however sometimes it seems to make a cookie, but rarely.

fafa
13 Nov, 2023, 17:04

(using the example btw)

Drake
13 Nov, 2023, 17:05

The cookie is should always be set (when the session is created client side). Maybe if you weren't using HTTPS or if there's some other SSL issue between the client and Appwrite.

fafa
13 Nov, 2023, 17:05

Alright, thanks.

fafa
13 Nov, 2023, 17:19

[SOLVED] Can I use appwrite sdk using nextjs server components?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more