You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improved credentials management and error handling. Credentials are invalidated when they expire or become invalid based on responses from the PowerSync service. The frequency of credential fetching has been reduced as a result of this work.
`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`
170
+
`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`
142
171
);
143
172
}
144
-
returnthis.credentials;
173
+
174
+
returncredentials;
175
+
}
176
+
177
+
/***
178
+
* Immediately invalidate credentials.
179
+
*
180
+
* This may be called when the current credentials have expired.
181
+
*/
182
+
invalidateCredentials(){
183
+
this.credentials=null;
184
+
this.connector.invalidateCredentials?.();
145
185
}
146
186
147
187
getUserAgent(){
@@ -181,6 +221,10 @@ export abstract class AbstractRemote {
181
221
body: JSON.stringify(data)
182
222
});
183
223
224
+
if(res.status===401){
225
+
this.invalidateCredentials();
226
+
}
227
+
184
228
if(!res.ok){
185
229
thrownewError(`Received ${res.status} - ${res.statusText} when posting to ${path}: ${awaitres.text()}}`);
186
230
}
@@ -198,6 +242,10 @@ export abstract class AbstractRemote {
198
242
}
199
243
});
200
244
245
+
if(res.status===401){
246
+
this.invalidateCredentials();
247
+
}
248
+
201
249
if(!res.ok){
202
250
thrownewError(`Received ${res.status} - ${res.statusText} when getting from ${path}: ${awaitres.text()}}`);
203
251
}
@@ -224,6 +272,10 @@ export abstract class AbstractRemote {
224
272
throwex;
225
273
});
226
274
275
+
if(res.status===401){
276
+
this.invalidateCredentials();
277
+
}
278
+
227
279
if(!res.ok){
228
280
consttext=awaitres.text();
229
281
this.logger.error(`Could not POST streaming to ${path} - ${res.status} - ${res.statusText}: ${text}`);
@@ -260,10 +312,19 @@ export abstract class AbstractRemote {
0 commit comments