Back

Best way to dev on localhost with cookies?

  • 1
  • Self Hosted
  • Auth
  • Web
MYND
2 Apr, 2024, 20:40

I'm sure this question has been answered before, but I couldn't find a good solution. I am new to Appwrite, and I'm selfhosting it at console.domain.com. I've set up a user account that I am trying to create an email session with. I get logged in, but the cookies don't set and as soon as I refresh, it acts like I am logged out even though the session is still active in the appwrite console. I have set the domain in the Web platform in the console to * hoping that would fix the issue but unfortunately it does not.

What is the best way to develop an application locally with auth while hosting the appwrite console on a different domain? I can see the session getting created in the dev console, so that part all works. Do I need to set something in my hosts file?

TL;DR
Developers discussing issues with cookies not saving for localhost. Solution: Configure domain and SSL correctly, cookies will not show up in the browser until actually used. Try making an `account.get()` request to make cookies show up. Running Appwrite locally resolved the issue for one developer.
Kenny
2 Apr, 2024, 20:48

I believe your apps domain and the domain for appwrite have to be the same for it to set cookies

Kenny
2 Apr, 2024, 20:48

you can have multiple domains for appwrite

MYND
2 Apr, 2024, 20:56

So I'd have to run appwrite locally for it to work?

VincentGe
2 Apr, 2024, 20:58

The fact that the cookies are not saved is browser behavior :/

VincentGe
2 Apr, 2024, 20:59

What cookies get saved where is not something we/you/sdk control with code

VincentGe
2 Apr, 2024, 20:59

The browser decides that is allowed and what isn't

MYND
2 Apr, 2024, 21:00

Is there a workaround or a browser setting/different browser I can try? Or should I just go the route of deploying my changes to something like vercel?

VincentGe
2 Apr, 2024, 21:01

Try running Appwrite locally

VincentGe
2 Apr, 2024, 21:01

I think it'll play nice(er)

MYND
2 Apr, 2024, 21:05

I will give that a shot, should be fairly easy. Thank You

VincentGe
2 Apr, 2024, 21:50

My memory is fuzzy because I haven't touched my self-hosted setup on a long while. What browser are you using btw?

VincentGe
2 Apr, 2024, 21:51

I believe we fall back to local storage for localhost

VincentGe
2 Apr, 2024, 21:52

For me, it still works on localhost :/

VincentGe
2 Apr, 2024, 21:52

but I know it could be problematic

MYND
2 Apr, 2024, 22:28

Firefox, chrome, edge, they all give similar results. I will give the hosting locally a shot, it makes the most sense for now

MYND
2 Apr, 2024, 23:32

The fallback cookie is there in localstorage but it doesn't seem to recognize my active session. Then again, Im fairly new to this and Im just cramming all the knowledge into my brain

Faye
3 Apr, 2024, 00:23

Fallback is not your cookie, the cookie should be under cookies.

The cookies will not show up in your browser until you actually use them.

This is because the domain the cookies are on, is not the same domain as localhost, but don't worry!

Try making a account.get() request, it should world fine and your cookies will show up.

MYND
3 Apr, 2024, 01:05

Running Appwrite locally made this work, I can now log in, refresh the page, and it still has me as logged in

VincentGe
4 Apr, 2024, 15:59

Yeah sounds like browser behavior 😐

VincentGe
4 Apr, 2024, 16:00

Glad you have a solution 🙂 This will also work with some config for your self-hosted instance, but I believe it has to do with configuring domain + SSL correctly? I honestly don't remember.

VincentGe
4 Apr, 2024, 16:00

@Steven What was the issue with cookies not saving for localhost again?

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