@meistrari/auth-nuxt 3.1.1 → 3.2.1

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
3
  "configKey": "telaAuth",
4
- "version": "3.1.1",
4
+ "version": "3.2.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,4 +1,5 @@
1
- import type { FullOrganization } from '@meistrari/auth-core';
1
+ import type { Ref } from 'vue';
2
+ import type { FullOrganization, User } from '@meistrari/auth-core';
2
3
  /**
3
4
  * Composable for managing Tela application authentication with OAuth 2.0 PKCE flow
4
5
  *
@@ -34,6 +35,8 @@ import type { FullOrganization } from '@meistrari/auth-core';
34
35
  * ```
35
36
  */
36
37
  export declare function useTelaApplicationAuth(): {
38
+ user: Ref<User | null>;
39
+ activeOrganization: Ref<FullOrganization | null>;
37
40
  login: () => Promise<void>;
38
41
  logout: () => Promise<void>;
39
42
  initSession: () => Promise<void>;
@@ -41,42 +44,4 @@ export declare function useTelaApplicationAuth(): {
41
44
  switchOrganization: (organizationId: string) => Promise<void>;
42
45
  refreshToken: () => Promise<void>;
43
46
  getToken: () => Promise<string | null | undefined>;
44
- user: import("vue").Ref<import("better-auth").StripEmptyObjects<{
45
- id: string;
46
- createdAt: Date;
47
- updatedAt: Date;
48
- email: string;
49
- emailVerified: boolean;
50
- name: string;
51
- image?: string | null | undefined;
52
- } & {
53
- twoFactorEnabled: boolean | null | undefined;
54
- } & {
55
- banned: boolean | null | undefined;
56
- } & {
57
- role?: string | null | undefined;
58
- banReason?: string | null | undefined;
59
- banExpires?: Date | null | undefined;
60
- } & {
61
- lastActiveAt?: Date | null | undefined;
62
- }> | null, import("better-auth").StripEmptyObjects<{
63
- id: string;
64
- createdAt: Date;
65
- updatedAt: Date;
66
- email: string;
67
- emailVerified: boolean;
68
- name: string;
69
- image?: string | null | undefined;
70
- } & {
71
- twoFactorEnabled: boolean | null | undefined;
72
- } & {
73
- banned: boolean | null | undefined;
74
- } & {
75
- role?: string | null | undefined;
76
- banReason?: string | null | undefined;
77
- banExpires?: Date | null | undefined;
78
- } & {
79
- lastActiveAt?: Date | null | undefined;
80
- }> | null>;
81
- activeOrganization: import("vue").Ref<FullOrganization | null, FullOrganization | null>;
82
47
  };
@@ -1,125 +1,20 @@
1
- import type { FullOrganization } from '@meistrari/auth-core';
1
+ import type { Ref } from 'vue';
2
+ import type { FullOrganization, Session, User } from '@meistrari/auth-core';
2
3
  /**
3
4
  * Shared state for session management.
4
5
  * This module provides access to session-related state without creating circular dependencies.
5
6
  */
6
7
  export declare function useSessionState(): {
7
- user: import("vue").Ref<import("better-auth").StripEmptyObjects<{
8
- id: string;
9
- createdAt: Date;
10
- updatedAt: Date;
11
- email: string;
12
- emailVerified: boolean;
13
- name: string;
14
- image?: string | null | undefined;
15
- } & {
16
- twoFactorEnabled: boolean | null | undefined;
17
- } & {
18
- banned: boolean | null | undefined;
19
- } & {
20
- role?: string | null | undefined;
21
- banReason?: string | null | undefined;
22
- banExpires?: Date | null | undefined;
23
- } & {
24
- lastActiveAt?: Date | null | undefined;
25
- }> | null, import("better-auth").StripEmptyObjects<{
26
- id: string;
27
- createdAt: Date;
28
- updatedAt: Date;
29
- email: string;
30
- emailVerified: boolean;
31
- name: string;
32
- image?: string | null | undefined;
33
- } & {
34
- twoFactorEnabled: boolean | null | undefined;
35
- } & {
36
- banned: boolean | null | undefined;
37
- } & {
38
- role?: string | null | undefined;
39
- banReason?: string | null | undefined;
40
- banExpires?: Date | null | undefined;
41
- } & {
42
- lastActiveAt?: Date | null | undefined;
43
- }> | null>;
44
- session: import("vue").Ref<{
45
- user: import("better-auth").StripEmptyObjects<{
46
- id: string;
47
- createdAt: Date;
48
- updatedAt: Date;
49
- email: string;
50
- emailVerified: boolean;
51
- name: string;
52
- image?: string | null | undefined;
53
- } & {
54
- twoFactorEnabled: boolean | null | undefined;
55
- } & {} & {
56
- banned: boolean | null | undefined;
57
- } & {
58
- role?: string | null | undefined;
59
- banReason?: string | null | undefined;
60
- banExpires?: Date | null | undefined;
61
- } & {} & {
62
- lastActiveAt?: Date | null | undefined;
63
- }>;
64
- session: import("better-auth").StripEmptyObjects<{
65
- id: string;
66
- createdAt: Date;
67
- updatedAt: Date;
68
- userId: string;
69
- expiresAt: Date;
70
- token: string;
71
- ipAddress?: string | null | undefined;
72
- userAgent?: string | null | undefined;
73
- } & {} & {
74
- activeOrganizationId?: string | null | undefined;
75
- activeTeamId?: string | null | undefined;
76
- } & {} & {
77
- impersonatedBy?: string | null | undefined;
78
- } & {} & {}>;
79
- } | null, {
80
- user: import("better-auth").StripEmptyObjects<{
81
- id: string;
82
- createdAt: Date;
83
- updatedAt: Date;
84
- email: string;
85
- emailVerified: boolean;
86
- name: string;
87
- image?: string | null | undefined;
88
- } & {
89
- twoFactorEnabled: boolean | null | undefined;
90
- } & {} & {
91
- banned: boolean | null | undefined;
92
- } & {
93
- role?: string | null | undefined;
94
- banReason?: string | null | undefined;
95
- banExpires?: Date | null | undefined;
96
- } & {} & {
97
- lastActiveAt?: Date | null | undefined;
98
- }>;
99
- session: import("better-auth").StripEmptyObjects<{
100
- id: string;
101
- createdAt: Date;
102
- updatedAt: Date;
103
- userId: string;
104
- expiresAt: Date;
105
- token: string;
106
- ipAddress?: string | null | undefined;
107
- userAgent?: string | null | undefined;
108
- } & {} & {
109
- activeOrganizationId?: string | null | undefined;
110
- activeTeamId?: string | null | undefined;
111
- } & {} & {
112
- impersonatedBy?: string | null | undefined;
113
- } & {} & {}>;
114
- } | null>;
8
+ user: Ref<User | null>;
9
+ session: Ref<Session | null>;
115
10
  };
116
11
  /**
117
12
  * Shared state for organization management.
118
13
  * This module provides access to organization-related state without creating circular dependencies.
119
14
  */
120
15
  export declare function useOrganizationState(): {
121
- activeOrganization: import("vue").Ref<FullOrganization | null, FullOrganization | null>;
122
- activeMember: import("vue").Ref<{
16
+ activeOrganization: Ref<FullOrganization | null, FullOrganization | null>;
17
+ activeMember: Ref<{
123
18
  id: string;
124
19
  organizationId: string;
125
20
  role: "org:admin" | "org:member" | "org:reviewer";
@@ -148,42 +43,6 @@ export declare function useOrganizationState(): {
148
43
  } | null>;
149
44
  };
150
45
  export declare function useApplicationSessionState(): {
151
- user: import("vue").Ref<import("better-auth").StripEmptyObjects<{
152
- id: string;
153
- createdAt: Date;
154
- updatedAt: Date;
155
- email: string;
156
- emailVerified: boolean;
157
- name: string;
158
- image?: string | null | undefined;
159
- } & {
160
- twoFactorEnabled: boolean | null | undefined;
161
- } & {
162
- banned: boolean | null | undefined;
163
- } & {
164
- role?: string | null | undefined;
165
- banReason?: string | null | undefined;
166
- banExpires?: Date | null | undefined;
167
- } & {
168
- lastActiveAt?: Date | null | undefined;
169
- }> | null, import("better-auth").StripEmptyObjects<{
170
- id: string;
171
- createdAt: Date;
172
- updatedAt: Date;
173
- email: string;
174
- emailVerified: boolean;
175
- name: string;
176
- image?: string | null | undefined;
177
- } & {
178
- twoFactorEnabled: boolean | null | undefined;
179
- } & {
180
- banned: boolean | null | undefined;
181
- } & {
182
- role?: string | null | undefined;
183
- banReason?: string | null | undefined;
184
- banExpires?: Date | null | undefined;
185
- } & {
186
- lastActiveAt?: Date | null | undefined;
187
- }> | null>;
188
- activeOrganization: import("vue").Ref<FullOrganization | null, FullOrganization | null>;
46
+ user: Ref<User | null>;
47
+ activeOrganization: Ref<FullOrganization | null>;
189
48
  };
@@ -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
- async function scheduleTokenRefresh() {
69
- if (tokenRefreshInterval) {
70
- clearTimeout(tokenRefreshInterval);
71
- tokenRefreshInterval = null;
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
- tokenRefreshInterval = window.setTimeout(() => void refreshToken(), nextRefresh);
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
  });
@@ -1,3 +1,4 @@
1
+ import type { FullOrganization, User } from '@meistrari/auth-core';
1
2
  /**
2
3
  * Server route handler for token refresh
3
4
  *
@@ -11,25 +12,7 @@
11
12
  */
12
13
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
13
14
  success: boolean;
14
- user: import("better-auth").StripEmptyObjects<{
15
- id: string;
16
- createdAt: Date;
17
- updatedAt: Date;
18
- email: string;
19
- emailVerified: boolean;
20
- name: string;
21
- image?: string | null | undefined;
22
- } & {
23
- twoFactorEnabled: boolean | null | undefined;
24
- } & {
25
- banned: boolean | null | undefined;
26
- } & {
27
- role?: string | null | undefined;
28
- banReason?: string | null | undefined;
29
- banExpires?: Date | null | undefined;
30
- } & {
31
- lastActiveAt?: Date | null | undefined;
32
- }>;
33
- organization: import("@meistrari/auth-core").FullOrganization;
15
+ user: User;
16
+ organization: FullOrganization;
34
17
  }>>;
35
18
  export default _default;
@@ -1,3 +1,4 @@
1
+ import type { FullOrganization, User } from '@meistrari/auth-core';
1
2
  /**
2
3
  * Server route handler for switching organizations
3
4
  *
@@ -12,25 +13,7 @@
12
13
  */
13
14
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
14
15
  success: boolean;
15
- user: import("better-auth").StripEmptyObjects<{
16
- id: string;
17
- createdAt: Date;
18
- updatedAt: Date;
19
- email: string;
20
- emailVerified: boolean;
21
- name: string;
22
- image?: string | null | undefined;
23
- } & {
24
- twoFactorEnabled: boolean | null | undefined;
25
- } & {
26
- banned: boolean | null | undefined;
27
- } & {
28
- role?: string | null | undefined;
29
- banReason?: string | null | undefined;
30
- banExpires?: Date | null | undefined;
31
- } & {
32
- lastActiveAt?: Date | null | undefined;
33
- }>;
34
- organization: import("@meistrari/auth-core").FullOrganization;
16
+ user: User;
17
+ organization: FullOrganization;
35
18
  }>>;
36
19
  export default _default;
@@ -1,24 +1,7 @@
1
+ import type { FullOrganization, User } from '@meistrari/auth-core';
1
2
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
3
  success: boolean;
3
- user: import("better-auth").StripEmptyObjects<{
4
- id: string;
5
- createdAt: Date;
6
- updatedAt: Date;
7
- email: string;
8
- emailVerified: boolean;
9
- name: string;
10
- image?: string | null | undefined;
11
- } & {
12
- twoFactorEnabled: boolean | null | undefined;
13
- } & {
14
- banned: boolean | null | undefined;
15
- } & {
16
- role?: string | null | undefined;
17
- banReason?: string | null | undefined;
18
- banExpires?: Date | null | undefined;
19
- } & {
20
- lastActiveAt?: Date | null | undefined;
21
- }>;
22
- organization: import("@meistrari/auth-core").FullOrganization;
4
+ user: User;
5
+ organization: FullOrganization;
23
6
  }>>;
24
7
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
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": "workspace:*",
38
+ "@meistrari/auth-core": "1.11.8",
39
39
  "jose": "6.1.3"
40
40
  },
41
41
  "peerDependencies": {