Back

[SOLVED] `cookieFallback` in localStorage suddenly stopped working

  • 0
  • Accounts
  • Web
  • Cloud
manazo
5 Jan, 2024, 16:32

in the initial stage of developing my app, i thot to handle the session in server-side only. then as the app have grown, i felt the need of client-side session as well (mainly for realtime connection). so i decided to maintain both client and server side sessions. for server-side i'm setting all the cookies and stuff, and everything there working quite perfectly. for client-side session, i'm just setting the cookieFallback value from X-Fallback-Cookies header in the localStorage. it was working perfectly. but suddenly it stopped working. when i hit the /account route for getting the currently logged-in user, it says unauthorized now. idk why it's happening. i'm not so sure which part of my code to even put here to debug this.

I also have tried comparing the X-Fallback-Cookies value i'm sending with every request from both client and server side. both are same

Stack: NextJS@14 Appwrite: Cloud Login System: Email-Password

lemme know if u need more info

TL;DR
[SOLVED] The issue was with the `cookieFallback` in localStorage suddenly stopping to work. The problem arose because Appwrite won't return the fallback cookie header if a custom domain is set. The solution is to delete the project cookies, which can be done from the Appwrite console by opening the browser dev tools, switching to the application tab, and then deleting the project cookie. There are two cookies for the project - one for the console user connecting to the Appwrite console and the other for the end user of the project. Deleting the project cookie should resolve the issue.
Drake
5 Jan, 2024, 16:40

you really should be using cookies in production rather than the fallback cookie header

manazo
5 Jan, 2024, 16:42

yeah i know. that's the recommended option. but i'm in local development now. so at least for local development, i need the fallback cookie header

Drake
5 Jan, 2024, 16:49

for client-side session, i'm just setting the cookieFallback value from X-Fallback-Cookies header in the localStorage. it was working perfectly.

How are you creating the session and setting the header?

I also have tried comparing the X-Fallback-Cookies value i'm sending with every request from both client and server side. both are same

Would you please share?

manazo
5 Jan, 2024, 17:29

this is the headers object i'm passing with every request. one ss is from browser console and another from terminal

Drake
5 Jan, 2024, 17:33

how about in the actual network request (network logs from browser dev tools)?

manazo
5 Jan, 2024, 17:40

i'm seeing two request to /account in the network tab. one's status code is 204 and one's is 401

manazo
5 Jan, 2024, 17:40

204's request headers:

manazo
5 Jan, 2024, 17:40

401's request headers:

Drake
5 Jan, 2024, 18:01

Interesting...I think this looks okay. How many sessions does the user have?

manazo
5 Jan, 2024, 18:04

one

Drake
5 Jan, 2024, 18:05

Wait, there's another cookie. Can you try deleting that cookie?

manazo
5 Jan, 2024, 18:09

i think it's from the appwrite console, to manage my login session there

Drake
5 Jan, 2024, 18:10

There are 2 cookies. The a_session_console one is for your console user connecting to the appwrite console. The other one is for the end user of your project

manazo
5 Jan, 2024, 18:14

yeah that's what I'm saying. so for my project, it has one cookie only, right?. or i'm missing something?

Drake
5 Jan, 2024, 19:22

Your browser has two cookies. You need to delete the project one

manazo
6 Jan, 2024, 04:26

I've tried it from an incognito window and it worked. there I noticed under the request headers of /account request, I don't have the Cookies value which I'm getting in the normal window. It means it's getting conflicted with some other cookies. now speaking of deleting the project's cookie, i'm not so sure how to do it. do i have to do it from the browser? or from the code?

Drake
6 Jan, 2024, 04:27

Go to the appwrite console, open the browser dev tools, switch to the application tab and then cookies

manazo
6 Jan, 2024, 04:30

i see it has cookies for my project. should i delete these? and i wonder why it has cookies for my project.

Drake
6 Jan, 2024, 04:31

Yes, delete the project cookies. They're always set by Appwrite. The browser doesn't always use them so that's why we have the fallback

manazo
6 Jan, 2024, 04:33

oh i get it. so when i'll go for a custom domain for appwrite, it'll work with the cookies by default instead of the fallback

Drake
6 Jan, 2024, 04:34

Yes, there will be no fallback cookie client side

manazo
6 Jan, 2024, 04:35

but isn't the fallback cookie and the main cookie value same? if yes, then it should work with the fallback as well i think?

Drake
6 Jan, 2024, 04:36

Sort of yes. Appwrite won't return the fallback cookie header if the custom domain is set. The cookies are http only so they can't be accessed using JavaScript

manazo
6 Jan, 2024, 04:38

[SOLVED] cookieFallback in localStorage suddenly stopped working

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