Skip to content

Commit f9cb3da

Browse files
committed
Correct command for token refresh
1 parent a0f527c commit f9cb3da

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ The next upload iteration will be delayed.`);
704704
const adapter = this.options.adapter;
705705
const remote = this.options.remote;
706706
let hideDisconnectOnRestart = false;
707+
let notifyTokenRefreshed: (() => void) | undefined;
707708

708709
if (signal.aborted) {
709710
throw new AbortOperation('Connection request has been aborted');
@@ -778,7 +779,7 @@ The next upload iteration will be delayed.`);
778779
// Restart iteration after the credentials have been refreshed.
779780
remote.fetchCredentials().then(
780781
(_) => {
781-
syncImplementation.notifyCompletedUploads?.();
782+
notifyTokenRefreshed?.();
782783
},
783784
(err) => {
784785
syncImplementation.logger.warn('Could not prefetch credentials', err);
@@ -834,6 +835,11 @@ The next upload iteration will be delayed.`);
834835
payload: JSON.stringify(this.activeStreams)
835836
});
836837
};
838+
notifyTokenRefreshed = () => {
839+
controlInvocations.inject({
840+
command: PowerSyncControlCommand.NOTIFY_TOKEN_REFRESHED
841+
});
842+
};
837843

838844
let hadSyncLine = false;
839845
loop: while (true) {
@@ -855,7 +861,7 @@ The next upload iteration will be delayed.`);
855861
const instructions = await invokePowerSyncControl(value.command, value.payload);
856862
for (const instruction of instructions) {
857863
if ('EstablishSyncStream' in instruction) {
858-
this.logger.warn('Received EstablishSyncStream while already connected.');
864+
throw new Error('Received EstablishSyncStream while already connected.');
859865
} else if ('CloseSyncStream' in instruction) {
860866
hideDisconnectOnRestart = instruction.CloseSyncStream.hide_disconnect;
861867
break loop;
@@ -866,6 +872,7 @@ The next upload iteration will be delayed.`);
866872
}
867873
} finally {
868874
this.notifyCompletedUploads = this.handleActiveStreamsChange = undefined;
875+
notifyTokenRefreshed = undefined;
869876
await stop();
870877
}
871878

0 commit comments

Comments
 (0)