Back

Issue with Session Cookie Persistence After Login (Appwrite + Next.js)

  • 0
  • Auth
  • Web
  • Cloud
Pondia
15 Oct, 2024, 11:45

Hello everyone,

I’m having trouble ensuring that session cookies persist after login. I’m aware that modern browsers block third-party cookies, and I’ve gone through https://appwrite.io/docs/advanced/platform/custom-domains, but I still can’t get the cookie to stick.

Setup:

Backend: Appwrite Cloud Frontend: Next.js I’ve tried two different approaches: locally and in production, but both result in the same issue.

Local Setup: I’ve modified my /etc/hosts file to map mydomain.com to localhost. Configured Appwrite's domain in the console to cloud.dev.mydomain.com via DNS. I’m running my local environment over HTTPS (https://mydomain.com). I created a user account with email/password successfully, and the session cookie appears in Chrome's Cookie tab after login. However, when I refresh the page or navigate to a different route, the cookie disappears, even though I expect it to persist.

Production Setup: The DNS is configured similarly, with cloud.mydomain.com for Appwrite and www.mydomain.com for the frontend. I’m facing the exact same issue as in the local environment. I can see that the session is successfully created in Appwrite’s Auth console for the test user. I can also retrieve this session using getSession("current"), but the session cookie just doesn't persist across page reloads or route changes.

I also tried accessing cookies in my Next.js middleware from the request object. I can retrieve other cookies (like NEXT_LOCALE), but the Appwrite session cookie is missing after a page refresh.

Has anyone experienced a similar issue or have any advice on how to resolve this? I don't understand what I missing here.

Thanks in advance!

TL;DR
Issue: Session cookies are not persisting after login in Appwrite + Next.js setup. Solution: The developers are experiencing problems with session cookies not persisting after login both locally and in production, despite following the necessary configurations. The session cookie appears after login but disappears upon page refresh or route change. The developers have tried different approaches, including modifying the hosts file, configuring Appwrite's domain, and accessing cookies in the Next.js middleware without success. They are seeking advice or solutions to resolve this persistence issue.
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