appwrite / appwrite/sdk-for-dart

🐛 Bug Report: Cookies aren't passed

Open
#90 6 comments 0 reactions 0 assignees View on GitHub
bug question
Dominant language
Dart
Stars
118
Forks
22
Avg merge
8h 16m
Merged PRs (30d)
3

Description

### 👟 Reproduction steps

When I use this package: dart_appwrite: 16.1.0 in my jaspr project and I try to sign in to create a session the cookies aren't passed. I first tried figuring out if it was some security issue but I got it working by manually sending the requests.
For example when I run this code:
```dart
var acc = Account(client);
await acc.createEmailPasswordSession(email: email, password: password);
await acc.getSession(sessionId: 'current');
```
I get the cookie from my self hosted server:

Image

But the get current session request does not have the cookies attached when sending the request:

Image

### 👍 Expected behavior

When I send it manually like this:
```dart
final response = await html.HttpRequest.request(
url,
method: 'POST',
requestHeaders: {
'Content-Type': 'application/json',
'X-Appwrite-Project': value,
},
sendData: jsonEncode({
'email': email,
'password': password,
}),
withCredentials: true, // <-- this is essential
)
```
And I request the session again:
```dart
final response = await html.HttpRequest.request(
'$endPoint/account/sessions/current',
method: 'GET',
requestHeaders: {
'X-Appwrite-Project': value,
},
withCredentials: true,
)
```
The cookies are attached correctly:

Image

So I tried to patch this package locally but I couldn't get it to work but I'm almost certain its in this line:https://github.com/appwrite/sdk-for-dart/blob/16a740317f50088697d44e95b9eae09d854310f4/lib/src/client_browser.dart#L27

Which should be:
```dart
_httpClient = BrowserClient()..withCredentials = true;
```
Maybe I'm wrong but let me know if I am :)

### 👎 Actual Behavior

Cookies aren't send.

### 🎲 Appwrite version

Version 0.10.x

### 💻 Operating system

Linux

### 🧱 Your Environment

_No response_

### 👀 Have you spent some time to check if this issue has been raised before?

- [x] I checked and didn't find similar issue

### 🏢 Have you read the Code of Conduct?

- [x] I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)

Contributor guide

Open the contributing guide

Research direction

Start in lib/src/client_browser.dart at the BrowserClient initialization referenced by the issue, then reproduce the createEmailPasswordSession and getSession calls in a browser-based Jaspr project. Compare the SDK requests with the manual html.HttpRequest requests using withCredentials: true; done means session cookies are attached and the current-session request succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.