@meistrari/auth-nuxt 3.2.0 → 3.3.0
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/module.json
CHANGED
|
@@ -24,6 +24,11 @@ export interface UseTelaApiKey {
|
|
|
24
24
|
* @returns A list of API keys
|
|
25
25
|
*/
|
|
26
26
|
listApiKeys: ApiKeyClient['listApiKeys'];
|
|
27
|
+
/**
|
|
28
|
+
* Lists all API keys of the active organization.
|
|
29
|
+
* @returns A list of API keys
|
|
30
|
+
*/
|
|
31
|
+
listOrganizationApiKeys: ApiKeyClient['listOrganizationApiKeys'];
|
|
27
32
|
/**
|
|
28
33
|
* Retrieves an existing API key.
|
|
29
34
|
* @param id - The ID of the API key to retrieve
|
|
@@ -16,6 +16,9 @@ export function useTelaApiKey() {
|
|
|
16
16
|
async function listApiKeys() {
|
|
17
17
|
return await authClient.apiKey.listApiKeys();
|
|
18
18
|
}
|
|
19
|
+
async function listOrganizationApiKeys() {
|
|
20
|
+
return await authClient.apiKey.listOrganizationApiKeys();
|
|
21
|
+
}
|
|
19
22
|
async function getApiKey(id) {
|
|
20
23
|
return await authClient.apiKey.getApiKey(id);
|
|
21
24
|
}
|
|
@@ -24,6 +27,7 @@ export function useTelaApiKey() {
|
|
|
24
27
|
updateApiKey,
|
|
25
28
|
deleteApiKey,
|
|
26
29
|
listApiKeys,
|
|
30
|
+
listOrganizationApiKeys,
|
|
27
31
|
getApiKey
|
|
28
32
|
};
|
|
29
33
|
}
|
|
@@ -29,8 +29,9 @@ export default defineNuxtPlugin({
|
|
|
29
29
|
maxAge: SEVEN_DAYS
|
|
30
30
|
});
|
|
31
31
|
const authClient = createNuxtAuthClient(appConfig.apiUrl, () => null, () => refreshTokenCookie.value ?? null);
|
|
32
|
-
let tokenRefreshInterval = null;
|
|
33
32
|
let isRefreshing = false;
|
|
33
|
+
let refreshWorker = null;
|
|
34
|
+
let workerAvailable = true;
|
|
34
35
|
async function refreshToken() {
|
|
35
36
|
if (isRefreshing) {
|
|
36
37
|
return;
|
|
@@ -65,11 +66,36 @@ export default defineNuxtPlugin({
|
|
|
65
66
|
state.user.value = null;
|
|
66
67
|
state.activeOrganization.value = null;
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
function scheduleWorkerTimeout(delayMs, callback) {
|
|
70
|
+
if (refreshWorker) {
|
|
71
|
+
refreshWorker.terminate();
|
|
72
|
+
refreshWorker = null;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const workerScript = `self.onmessage=function(e){setTimeout(function(){postMessage('tick')},e.data)}`;
|
|
76
|
+
const blob = new Blob([workerScript], { type: "application/javascript" });
|
|
77
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
78
|
+
const worker = new Worker(blobUrl);
|
|
79
|
+
URL.revokeObjectURL(blobUrl);
|
|
80
|
+
worker.onmessage = () => {
|
|
81
|
+
worker.terminate();
|
|
82
|
+
refreshWorker = null;
|
|
83
|
+
callback();
|
|
84
|
+
};
|
|
85
|
+
worker.onerror = () => {
|
|
86
|
+
worker.terminate();
|
|
87
|
+
refreshWorker = null;
|
|
88
|
+
workerAvailable = false;
|
|
89
|
+
window.setTimeout(callback, delayMs);
|
|
90
|
+
};
|
|
91
|
+
worker.postMessage(delayMs);
|
|
92
|
+
refreshWorker = worker;
|
|
93
|
+
} catch {
|
|
94
|
+
workerAvailable = false;
|
|
95
|
+
window.setTimeout(callback, delayMs);
|
|
72
96
|
}
|
|
97
|
+
}
|
|
98
|
+
async function scheduleTokenRefresh() {
|
|
73
99
|
if (!accessTokenCookie.value || isTokenExpired(accessTokenCookie.value, TWO_MINUTES)) {
|
|
74
100
|
const result = await refreshToken();
|
|
75
101
|
if (!result) {
|
|
@@ -81,7 +107,7 @@ export default defineNuxtPlugin({
|
|
|
81
107
|
return;
|
|
82
108
|
}
|
|
83
109
|
const nextRefresh = Math.max(expiry - TWO_MINUTES - Date.now(), 0);
|
|
84
|
-
|
|
110
|
+
scheduleWorkerTimeout(nextRefresh, () => void scheduleTokenRefresh());
|
|
85
111
|
}
|
|
86
112
|
if (import.meta.server) {
|
|
87
113
|
if (accessTokenCookie.value) {
|
|
@@ -128,6 +154,11 @@ export default defineNuxtPlugin({
|
|
|
128
154
|
}
|
|
129
155
|
}
|
|
130
156
|
void scheduleTokenRefresh();
|
|
157
|
+
document.addEventListener("visibilitychange", () => {
|
|
158
|
+
if (document.visibilityState === "visible" && !workerAvailable) {
|
|
159
|
+
void scheduleTokenRefresh();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
131
162
|
}
|
|
132
163
|
}
|
|
133
164
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/auth-nuxt",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@meistrari/auth-core": "1.
|
|
38
|
+
"@meistrari/auth-core": "1.13.1",
|
|
39
39
|
"jose": "6.1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|