From 78fc204a2a79c926ed26aa671a77d1e1f75421ac Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 8 Nov 2026 11:26:19 +0545 Subject: [PATCH 1/3] Send the app JWT in X-Refetch-JWT Appwrite Cloud's edge executor overwrites the Authorization header before a request reaches refetch.io, so every /api/app/* call answered 401 in production (the JWT itself checked out: 200 from Appwrite's /v1/account). Pairs with refetch-io/refetch#14. Co-Authored-By: Claude Opus 5.5 --- lib/core/network/api_client.dart | 8 +++++--- test/api_client_test.dart | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/core/network/api_client.dart b/lib/core/network/api_client.dart index 31f0b03..89936c0 100644 --- a/lib/core/network/api_client.dart +++ b/lib/core/network/api_client.dart @@ -11,8 +11,8 @@ import 'api_exception.dart'; /// see the web repo's `docs/APP_API.md`). /// /// Handles JSON encoding/decoding, unwrapping the `{ "data": … }` envelope, -/// error mapping to [ApiException], and injecting the cached Appwrite JWT as a -/// Bearer token on authenticated calls. +/// error mapping to [ApiException], and sending the cached Appwrite JWT in the +/// `X-Refetch-JWT` header on authenticated calls. class ApiClient { ApiClient({ required this.baseUrl, @@ -88,7 +88,9 @@ class ApiClient { if (token == null) { throw const ApiException(401, 'You need to sign in to do that.'); } - headers['authorization'] = 'Bearer $token'; + // Not `Authorization`: Appwrite Cloud's edge executor overwrites that + // header before the request reaches refetch.io (docs/APP_API.md). + headers['x-refetch-jwt'] = token; } return headers; } diff --git a/test/api_client_test.dart b/test/api_client_test.dart index d7d8e97..5501ba4 100644 --- a/test/api_client_test.dart +++ b/test/api_client_test.dart @@ -140,4 +140,26 @@ void main() { ), ); }); + + // Appwrite Cloud's edge executor overwrites Authorization before the request + // reaches refetch.io, so the JWT must travel in X-Refetch-JWT. + test('sends the JWT in X-Refetch-JWT, not Authorization', () async { + Map? sent; + when( + () => httpClient.post( + any(), + headers: any(named: 'headers'), + body: any(named: 'body'), + encoding: any(named: 'encoding'), + ), + ).thenAnswer((invocation) async { + sent = invocation.namedArguments[#headers] as Map; + return http.Response('{"data":{}}', 200); + }); + + await api.post('/api/app/session'); + + expect(sent?['x-refetch-jwt'], 't'); + expect(sent?.containsKey('authorization'), isFalse); + }); } From c84142cf62083c09c4d09e197847a6cee0297bc8 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 8 Nov 2026 11:26:19 +0545 Subject: [PATCH 2/3] Drop appwrite's unused background-push services from the manifest appwrite 28 brings an MQTT foreground service (remoteMessaging), flutter_background_service and boot receivers. Refetch pushes through FCM with the push plugin and never starts them; left in, the remoteMessaging foreground service needs a Play Console declaration and the receivers wake the app on every reboot. Removed with tools:node=remove, as the appwrite manifest suggests. The merged manifest keeps the push plugin's FCM receiver and MESSAGING_EVENT service. Co-Authored-By: Claude Opus 5.5 --- android/app/src/main/AndroidManifest.xml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e0445db..b764abf 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,4 +1,17 @@ - + + + + + + + + + + + + + + + +