@jskit-ai/auth-web 0.2.1 → 0.2.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"@mdi/js": "^7.4.47"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@jskit-ai/auth-core": "0.2.
|
|
30
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
31
|
-
"@jskit-ai/kernel": "0.2.
|
|
32
|
-
"@jskit-ai/shell-web": "0.2.
|
|
29
|
+
"@jskit-ai/auth-core": "0.2.2",
|
|
30
|
+
"@jskit-ai/http-runtime": "0.2.2",
|
|
31
|
+
"@jskit-ai/kernel": "0.2.2",
|
|
32
|
+
"@jskit-ai/shell-web": "0.2.2",
|
|
33
33
|
"@tanstack/vue-query": "^5.90.5",
|
|
34
34
|
"pinia": "^4.0.3",
|
|
35
35
|
"vue": "^3.5.44",
|
|
@@ -48,6 +48,7 @@ function createAuthClient({ mobile = null, pinia, realtime = null, shell, vueApp
|
|
|
48
48
|
const mobileCallback = createMobileCallbackCompleter();
|
|
49
49
|
const oauthLaunch = mobile?.oauthLaunch || createPopupOAuthLaunchClient();
|
|
50
50
|
let stopAuthRefresh = null;
|
|
51
|
+
let releaseBeforeReconnect = null;
|
|
51
52
|
|
|
52
53
|
async function initialize() {
|
|
53
54
|
if (!pinia) {
|
|
@@ -59,6 +60,9 @@ function createAuthClient({ mobile = null, pinia, realtime = null, shell, vueApp
|
|
|
59
60
|
stopAuthRefresh = authStore.subscribe(() => {
|
|
60
61
|
void shell.bootstrap.refresh("auth.state");
|
|
61
62
|
});
|
|
63
|
+
// A socket refused for an expired session reconnects with the cookies this
|
|
64
|
+
// session read stores.
|
|
65
|
+
releaseBeforeReconnect = realtime?.setBeforeReconnect(() => guard.refresh()) || null;
|
|
62
66
|
vueApp?.provide?.(AUTH_GUARD_RUNTIME_INJECTION_KEY, guard);
|
|
63
67
|
vueApp?.provide?.(AUTH_OAUTH_LAUNCH_CLIENT_INJECTION_KEY, oauthLaunch);
|
|
64
68
|
}
|
|
@@ -66,6 +70,8 @@ function createAuthClient({ mobile = null, pinia, realtime = null, shell, vueApp
|
|
|
66
70
|
function dispose() {
|
|
67
71
|
stopAuthRefresh?.();
|
|
68
72
|
stopAuthRefresh = null;
|
|
73
|
+
releaseBeforeReconnect?.();
|
|
74
|
+
releaseBeforeReconnect = null;
|
|
69
75
|
guard.dispose?.();
|
|
70
76
|
}
|
|
71
77
|
|
package/test/provider.test.js
CHANGED
|
@@ -40,6 +40,32 @@ test("auth client groups guard, OAuth, and mobile callback behavior without a co
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
test("auth client refreshes the session over HTTP before realtime reconnects", async (t) => {
|
|
44
|
+
const sessionReads = [];
|
|
45
|
+
t.mock.method(globalThis, "fetch", async (path) => {
|
|
46
|
+
sessionReads.push(path);
|
|
47
|
+
return { ok: true, status: 200, async json() { return { authenticated: false }; } };
|
|
48
|
+
});
|
|
49
|
+
let beforeReconnect = null;
|
|
50
|
+
let released = false;
|
|
51
|
+
const realtime = {
|
|
52
|
+
socket: null,
|
|
53
|
+
setBeforeReconnect(prepare) {
|
|
54
|
+
beforeReconnect = prepare;
|
|
55
|
+
return () => { released = true; };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const auth = createAuthClient({ pinia: createPinia(), realtime, shell: createShell(), vueApp: { provide() {} } });
|
|
59
|
+
await auth.initialize();
|
|
60
|
+
const readsAtStartup = sessionReads.length;
|
|
61
|
+
|
|
62
|
+
await beforeReconnect();
|
|
63
|
+
assert.equal(sessionReads.length, readsAtStartup + 1);
|
|
64
|
+
assert.equal(sessionReads.at(-1), "/api/session");
|
|
65
|
+
auth.dispose();
|
|
66
|
+
assert.equal(released, true);
|
|
67
|
+
});
|
|
68
|
+
|
|
43
69
|
assert.equal(typeof auth.guard.initialize, "function");
|
|
44
70
|
assert.equal(typeof auth.oauthLaunch.open, "function");
|
|
45
71
|
assert.equal(typeof auth.mobileCallback.completeFromUrl, "function");
|