Back

Appwrite SDK v1.6 is not sending Cookies with requests

  • 0
  • Self Hosted
  • Web
deep-printerverse
25 Sep, 2024, 12:19

In my dev server, everything worked fine but as soon as I pushed to staging, users were not able to login. I found the commit which caused the issue and that was when I updated Appwrite client SDK from 1.5 -> 1.6. I looked at the code to compare what changed.

After a user logs in using createEmailPasswordSession, the app redirects to /, which then gets the user account using account.get. This exact same code was working with SDK v1.5 but failed for SDK v1.6. I checked the code for account.get in both versions and it looked the same, so I checked the call method in Client class and noticed a difference between the two.

v1.5

TypeScript
let options: RequestInit = {
        method,
        headers,
        credentials: 'include'
    };

v1.6

TypeScript
let options: RequestInit = {
        method,
        headers
    };

By default, fetch does not include cookies. To include cookies in a fetch request, you need to set the credentials option to include or same-origin. SDK v1.5 used to have the correct options set, and I think v1.6 should do the same.

TL;DR
Appwrite SDK v1.6 isn't sending cookies with requests, causing login issues in staging. The problem stems from a change in the `Client` class `call` method between versions 1.5 and 1.6, specifically missing the `credentials: 'include'` option in v1.6. To solve, update SDK v1.6 to include the `credentials` option when making fetch requests.
darShan
25 Sep, 2024, 12:46

afaik this was probably done for ssr, i might be wrong. so in that case one would do sign in via server sdk, get secret and pass it to client sdk like - client.setSession.

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