Skip to content

Commit 9ca7981

Browse files
committed
Add Client-ID header.
1 parent f8dc564 commit 9ca7981

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/powersync/lib/src/streaming_sync.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class StreamingSyncImplementation {
5050
final Mutex syncMutex, crudMutex;
5151

5252
late final String? userAgent;
53+
String? clientId;
5354

5455
StreamingSyncImplementation(
5556
{required this.adapter,
@@ -103,6 +104,7 @@ class StreamingSyncImplementation {
103104
Future<void> streamingSync() async {
104105
try {
105106
_abort = AbortController();
107+
clientId = await adapter.getClientId();
106108
crudLoop();
107109
var invalidCredentials = false;
108110
while (!aborted) {
@@ -201,7 +203,8 @@ class StreamingSyncImplementation {
201203

202204
Map<String, String> headers = {
203205
'Content-Type': 'application/json',
204-
'Authorization': "Token ${credentials.token}"
206+
'Authorization': "Token ${credentials.token}",
207+
'Client-ID': clientId!
205208
};
206209
if (userAgent != null) {
207210
headers['User-Agent'] = userAgent!;
@@ -254,7 +257,6 @@ class StreamingSyncImplementation {
254257
{AbortController? abortController}) async {
255258
adapter.startSession();
256259
final bucketEntries = await adapter.getBucketStates();
257-
final clientId = await adapter.getClientId();
258260

259261
Map<String, String> initialBucketStates = {};
260262

@@ -273,7 +275,7 @@ class StreamingSyncImplementation {
273275
var bucketSet = Set<String>.from(initialBucketStates.keys);
274276

275277
var requestStream = streamingSyncRequest(
276-
StreamingSyncRequest(buckets, syncParameters, clientId));
278+
StreamingSyncRequest(buckets, syncParameters, clientId!));
277279

278280
var merged = addBroadcast(requestStream, _localPingController.stream);
279281

@@ -414,6 +416,7 @@ class StreamingSyncImplementation {
414416
final request = http.Request('POST', uri);
415417
request.headers['Content-Type'] = 'application/json';
416418
request.headers['Authorization'] = "Token ${credentials.token}";
419+
request.headers['Client-ID'] = clientId!;
417420
if (userAgent != null) {
418421
request.headers['User-Agent'] = userAgent!;
419422
}

0 commit comments

Comments
 (0)