Back

[Solved] How to get `cookieFallback` when making requests using Web SDK?

  • 0
  • Self Hosted
  • Accounts
  • Web
Binyamin
31 May, 2023, 13:20

Can you share a picture?

TL;DR
The user was asking if there is a way to get the `cookieFallback` when making requests using the Web SDK. Another user confirmed that the `cookieFallback` is accessible through the browser's cookie storage, but not visible for the `localhost` domain. They suggested accessing an Appwrite URL with the project ID to see the cookies. The user also mentioned that the browser does save the cookies and the `cookie` header is also set. They shared a screenshot showing the flow of Appwrite cookies logic. Finally, the user asked for a picture to get a better understanding.
Binyamin
31 May, 2023, 13:20

So I can get a better understanding

ashuvssut (ashu)
31 May, 2023, 13:21

I saw that the subsequent requests had a cookie header. I didn't check if it had a x-fallback-cookies header

ashuvssut (ashu)
31 May, 2023, 13:21

Just 4mins

Binyamin
31 May, 2023, 13:26

This is the flow of Appwrite cookies logic.

If the fetch added native browser cookies that can mean the maybe your browser do accept cookies.

This is part of Appwrite client call function

TypeScript
let options: RequestInit = {
    method,
    headers,
    credentials: 'include'
};
if (typeof window !== 'undefined' && window.localStorage) {
    headers['X-Fallback-Cookies'] = window.localStorage.getItem('cookieFallback') ?? '';
}
/* More code */

const response = await fetch(url.toString(), options);

You can see the setting of credentials: 'include' which tell the browser to pass any cookies and the adding of fallback one.

ashuvssut (ashu)
31 May, 2023, 13:27

so in this screenshot you can see -> create account POST, OPTIONS request -> create session with email POST, OPTIONS requst -> get accout GET request

ashuvssut (ashu)
31 May, 2023, 13:27

now

ashuvssut (ashu)
31 May, 2023, 13:27

here you were right about x-fallback-cookies being present in the request headers

ashuvssut (ashu)
31 May, 2023, 13:27

but also the cookie header is set too!

Binyamin
31 May, 2023, 13:27

So it looks like your browser do save the cookies.

ashuvssut (ashu)
31 May, 2023, 13:27

in cookieStorage there is no cookies

ashuvssut (ashu)
31 May, 2023, 13:28
ashuvssut (ashu)
31 May, 2023, 13:29

this is localStorage

Binyamin
31 May, 2023, 13:31

Ohh gotcha You won't see the cookies because the not saved for the localhost domain, but for the Appwrite one. So in order for you to be able to see them, you'll need to go to some Appwrite url like so https://cloud.appwrite.io/v1/account?project=6469040898e19fe9052c Replace this ID with your project ID.

Binyamin
31 May, 2023, 13:33

Then you'll have access to how the browser stores all the cookies for the current user.

ashuvssut (ashu)
31 May, 2023, 13:34

Ohh

ashuvssut (ashu)
31 May, 2023, 13:35

Yes

ashuvssut (ashu)
31 May, 2023, 13:35

Cross checked just now

ashuvssut (ashu)
31 May, 2023, 13:35

Thx!!

Binyamin
31 May, 2023, 13:36

<:appwriteupvote:899677724615016528>

ashuvssut (ashu)
31 May, 2023, 13:39

about the 1st question:- Does websdk have some way to return the fallback cookie on a successful response

ashuvssut (ashu)
31 May, 2023, 13:40

I have a use case for this thing

(The use case is described in the post description)

Binyamin
31 May, 2023, 13:41

I think that verification do pass in localhost (and in your react native) so it seems like no.

ashuvssut (ashu)
31 May, 2023, 13:41

Oh okay then

ashuvssut (ashu)
31 May, 2023, 13:42

[Solved] How to get cookieFallback when making requests using Web SDK?

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