@oxyhq/core 3.4.6 → 3.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/OxyServices.base.js +6 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/OxyServices.base.js +6 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/OxyServices.base.ts +7 -0
- package/src/__tests__/linkedClient.test.ts +28 -0
package/package.json
CHANGED
package/src/OxyServices.base.ts
CHANGED
|
@@ -151,6 +151,13 @@ export class OxyServicesBase {
|
|
|
151
151
|
const unsubscribe = this.onTokensChanged(syncToken);
|
|
152
152
|
client.setAuthRefreshHandler(async (reason: AuthRefreshReason) => {
|
|
153
153
|
const refreshed = await this.httpService.refreshAccessToken(reason);
|
|
154
|
+
if (!refreshed) {
|
|
155
|
+
if (reason === 'response-401') {
|
|
156
|
+
this.clearTokens();
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
154
161
|
syncToken(refreshed);
|
|
155
162
|
return refreshed;
|
|
156
163
|
});
|
|
@@ -49,6 +49,34 @@ describe('OxyServices.createLinkedClient', () => {
|
|
|
49
49
|
linked.dispose();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
it('clears the session owner when a linked response 401 cannot refresh', async () => {
|
|
53
|
+
const oxy = createServices();
|
|
54
|
+
oxy.setTokens('stale_access');
|
|
55
|
+
const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
|
|
56
|
+
|
|
57
|
+
const refreshed = await linked.client.refreshAccessToken('response-401');
|
|
58
|
+
|
|
59
|
+
expect(refreshed).toBeNull();
|
|
60
|
+
expect(oxy.getAccessToken()).toBeNull();
|
|
61
|
+
expect(linked.client.getAccessToken()).toBeNull();
|
|
62
|
+
|
|
63
|
+
linked.dispose();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('keeps the session owner intact when linked preflight refresh cannot refresh', async () => {
|
|
67
|
+
const oxy = createServices();
|
|
68
|
+
oxy.setTokens('existing_access');
|
|
69
|
+
const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
|
|
70
|
+
|
|
71
|
+
const refreshed = await linked.client.refreshAccessToken('preflight');
|
|
72
|
+
|
|
73
|
+
expect(refreshed).toBeNull();
|
|
74
|
+
expect(oxy.getAccessToken()).toBe('existing_access');
|
|
75
|
+
expect(linked.client.getAccessToken()).toBe('existing_access');
|
|
76
|
+
|
|
77
|
+
linked.dispose();
|
|
78
|
+
});
|
|
79
|
+
|
|
52
80
|
it('stops mirroring after dispose', () => {
|
|
53
81
|
const oxy = createServices();
|
|
54
82
|
const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
|