@meistrari/auth-nuxt 2.0.0 → 2.1.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 +1 -1
- package/dist/runtime/composables/application-auth.d.ts +32 -2
- package/dist/runtime/composables/application-auth.js +15 -2
- package/dist/runtime/composables/state.d.ts +86 -5
- package/dist/runtime/server/middleware/application-auth.js +3 -3
- package/dist/runtime/server/utils/require-auth.js +2 -2
- package/dist/runtime/shared.d.ts +2 -1
- package/package.json +51 -51
package/dist/module.json
CHANGED
|
@@ -36,6 +36,36 @@ export declare function useTelaApplicationAuth(): {
|
|
|
36
36
|
login: () => Promise<void>;
|
|
37
37
|
logout: () => Promise<void>;
|
|
38
38
|
initSession: () => Promise<void>;
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
getAvailableOrganizations: () => Promise<import("@meistrari/auth-core").Organization[]>;
|
|
40
|
+
switchOrganization: (organizationId: string) => Promise<void>;
|
|
41
|
+
user: import("vue").Ref<{
|
|
42
|
+
id: string;
|
|
43
|
+
createdAt: Date;
|
|
44
|
+
updatedAt: Date;
|
|
45
|
+
email: string;
|
|
46
|
+
emailVerified: boolean;
|
|
47
|
+
name: string;
|
|
48
|
+
image?: string | null | undefined;
|
|
49
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
50
|
+
banned: boolean | null | undefined;
|
|
51
|
+
role?: string | null | undefined;
|
|
52
|
+
banReason?: string | null | undefined;
|
|
53
|
+
banExpires?: Date | null | undefined;
|
|
54
|
+
lastActiveAt?: Date | null | undefined;
|
|
55
|
+
} | null, {
|
|
56
|
+
id: string;
|
|
57
|
+
createdAt: Date;
|
|
58
|
+
updatedAt: Date;
|
|
59
|
+
email: string;
|
|
60
|
+
emailVerified: boolean;
|
|
61
|
+
name: string;
|
|
62
|
+
image?: string | null | undefined;
|
|
63
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
64
|
+
banned: boolean | null | undefined;
|
|
65
|
+
role?: string | null | undefined;
|
|
66
|
+
banReason?: string | null | undefined;
|
|
67
|
+
banExpires?: Date | null | undefined;
|
|
68
|
+
lastActiveAt?: Date | null | undefined;
|
|
69
|
+
} | null>;
|
|
70
|
+
activeOrganization: import("vue").Ref<Omit<import("@meistrari/auth-core").FullOrganization, "members" | "invitations" | "teams"> | null, Omit<import("@meistrari/auth-core").FullOrganization, "members" | "invitations" | "teams"> | null>;
|
|
41
71
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { navigateTo, useCookie, useRoute, useRuntimeConfig } from "#app";
|
|
2
|
+
import { AuthorizationFlowError, isTokenExpired, RefreshTokenExpiredError } from "@meistrari/auth-core";
|
|
2
3
|
import { createNuxtAuthClient } from "../shared.js";
|
|
3
4
|
import { useApplicationSessionState } from "./state.js";
|
|
4
|
-
import { AuthorizationFlowError, isTokenExpired, RefreshTokenExpiredError } from "@meistrari/auth-core";
|
|
5
5
|
const SEVEN_DAYS = 60 * 60 * 24 * 7;
|
|
6
6
|
const FIFTEEN_MINUTES = 60 * 15;
|
|
7
7
|
const ONE_MINUTE = 60 * 1e3;
|
|
@@ -162,10 +162,23 @@ export function useTelaApplicationAuth() {
|
|
|
162
162
|
await refreshToken();
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
async function getAvailableOrganizations() {
|
|
166
|
+
const { organizations } = await authClient.application.listCandidateOrganizations(applicationId);
|
|
167
|
+
return organizations;
|
|
168
|
+
}
|
|
169
|
+
async function switchOrganization(organizationId) {
|
|
170
|
+
const { accessToken, refreshToken: refreshToken2, user, organization } = await authClient.application.switchOrganization(organizationId);
|
|
171
|
+
accessTokenCookie.value = accessToken;
|
|
172
|
+
refreshTokenCookie.value = refreshToken2;
|
|
173
|
+
state.user.value = user;
|
|
174
|
+
state.activeOrganization.value = mapOrganization(organization);
|
|
175
|
+
}
|
|
165
176
|
return {
|
|
166
177
|
...state,
|
|
167
178
|
login,
|
|
168
179
|
logout,
|
|
169
|
-
initSession
|
|
180
|
+
initSession,
|
|
181
|
+
getAvailableOrganizations,
|
|
182
|
+
switchOrganization
|
|
170
183
|
};
|
|
171
184
|
}
|
|
@@ -1,20 +1,101 @@
|
|
|
1
|
+
import type { FullOrganization, Member } from '@meistrari/auth-core';
|
|
1
2
|
/**
|
|
2
3
|
* Shared state for session management.
|
|
3
4
|
* This module provides access to session-related state without creating circular dependencies.
|
|
4
5
|
*/
|
|
5
6
|
export declare function useSessionState(): {
|
|
6
|
-
user: import("vue").Ref<
|
|
7
|
-
|
|
7
|
+
user: import("vue").Ref<{
|
|
8
|
+
id: string;
|
|
9
|
+
createdAt: Date;
|
|
10
|
+
updatedAt: Date;
|
|
11
|
+
email: string;
|
|
12
|
+
emailVerified: boolean;
|
|
13
|
+
name: string;
|
|
14
|
+
image?: string | null | undefined;
|
|
15
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
16
|
+
banned: boolean | null | undefined;
|
|
17
|
+
role?: string | null | undefined;
|
|
18
|
+
banReason?: string | null | undefined;
|
|
19
|
+
banExpires?: Date | null | undefined;
|
|
20
|
+
lastActiveAt?: Date | null | undefined;
|
|
21
|
+
} | null, {
|
|
22
|
+
id: string;
|
|
23
|
+
createdAt: Date;
|
|
24
|
+
updatedAt: Date;
|
|
25
|
+
email: string;
|
|
26
|
+
emailVerified: boolean;
|
|
27
|
+
name: string;
|
|
28
|
+
image?: string | null | undefined;
|
|
29
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
30
|
+
banned: boolean | null | undefined;
|
|
31
|
+
role?: string | null | undefined;
|
|
32
|
+
banReason?: string | null | undefined;
|
|
33
|
+
banExpires?: Date | null | undefined;
|
|
34
|
+
lastActiveAt?: Date | null | undefined;
|
|
35
|
+
} | null>;
|
|
36
|
+
session: import("vue").Ref<{
|
|
37
|
+
id: string;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
updatedAt: Date;
|
|
40
|
+
userId: string;
|
|
41
|
+
expiresAt: Date;
|
|
42
|
+
token: string;
|
|
43
|
+
ipAddress?: string | null | undefined;
|
|
44
|
+
userAgent?: string | null | undefined;
|
|
45
|
+
activeOrganizationId?: string | null | undefined;
|
|
46
|
+
activeTeamId?: string | null | undefined;
|
|
47
|
+
impersonatedBy?: string | null | undefined;
|
|
48
|
+
} | null, {
|
|
49
|
+
id: string;
|
|
50
|
+
createdAt: Date;
|
|
51
|
+
updatedAt: Date;
|
|
52
|
+
userId: string;
|
|
53
|
+
expiresAt: Date;
|
|
54
|
+
token: string;
|
|
55
|
+
ipAddress?: string | null | undefined;
|
|
56
|
+
userAgent?: string | null | undefined;
|
|
57
|
+
activeOrganizationId?: string | null | undefined;
|
|
58
|
+
activeTeamId?: string | null | undefined;
|
|
59
|
+
impersonatedBy?: string | null | undefined;
|
|
60
|
+
} | null>;
|
|
8
61
|
};
|
|
9
62
|
/**
|
|
10
63
|
* Shared state for organization management.
|
|
11
64
|
* This module provides access to organization-related state without creating circular dependencies.
|
|
12
65
|
*/
|
|
13
66
|
export declare function useOrganizationState(): {
|
|
14
|
-
activeOrganization: import("vue").Ref<
|
|
15
|
-
activeMember: import("vue").Ref<
|
|
67
|
+
activeOrganization: import("vue").Ref<FullOrganization | null, FullOrganization | null>;
|
|
68
|
+
activeMember: import("vue").Ref<Member | null, Member | null>;
|
|
16
69
|
};
|
|
17
70
|
export declare function useApplicationSessionState(): {
|
|
18
|
-
user: import("vue").Ref<
|
|
71
|
+
user: import("vue").Ref<{
|
|
72
|
+
id: string;
|
|
73
|
+
createdAt: Date;
|
|
74
|
+
updatedAt: Date;
|
|
75
|
+
email: string;
|
|
76
|
+
emailVerified: boolean;
|
|
77
|
+
name: string;
|
|
78
|
+
image?: string | null | undefined;
|
|
79
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
80
|
+
banned: boolean | null | undefined;
|
|
81
|
+
role?: string | null | undefined;
|
|
82
|
+
banReason?: string | null | undefined;
|
|
83
|
+
banExpires?: Date | null | undefined;
|
|
84
|
+
lastActiveAt?: Date | null | undefined;
|
|
85
|
+
} | null, {
|
|
86
|
+
id: string;
|
|
87
|
+
createdAt: Date;
|
|
88
|
+
updatedAt: Date;
|
|
89
|
+
email: string;
|
|
90
|
+
emailVerified: boolean;
|
|
91
|
+
name: string;
|
|
92
|
+
image?: string | null | undefined;
|
|
93
|
+
twoFactorEnabled: boolean | null | undefined;
|
|
94
|
+
banned: boolean | null | undefined;
|
|
95
|
+
role?: string | null | undefined;
|
|
96
|
+
banReason?: string | null | undefined;
|
|
97
|
+
banExpires?: Date | null | undefined;
|
|
98
|
+
lastActiveAt?: Date | null | undefined;
|
|
99
|
+
} | null>;
|
|
19
100
|
activeOrganization: import("vue").Ref<Omit<FullOrganization, "members" | "invitations" | "teams"> | null, Omit<FullOrganization, "members" | "invitations" | "teams"> | null>;
|
|
20
101
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
2
|
import { defineEventHandler, getCookie } from "h3";
|
|
3
3
|
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
4
4
|
async function setApplicationAuthContext(event) {
|
|
5
5
|
event.context.auth = {
|
|
6
6
|
user: null,
|
|
7
7
|
workspace: null,
|
|
8
|
-
token:
|
|
8
|
+
token: void 0
|
|
9
9
|
};
|
|
10
10
|
const token = getCookie(event, "tela-access-token");
|
|
11
11
|
if (!token) {
|
|
@@ -20,7 +20,7 @@ async function setApplicationAuthContext(event) {
|
|
|
20
20
|
try {
|
|
21
21
|
const payload = await jwtVerify(
|
|
22
22
|
token,
|
|
23
|
-
createRemoteJWKSet(new URL("
|
|
23
|
+
createRemoteJWKSet(new URL("/api/auth/jwks", apiUrl)),
|
|
24
24
|
{
|
|
25
25
|
issuer: apiUrl,
|
|
26
26
|
audience: applicationId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "
|
|
1
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
2
2
|
import { createError, defineEventHandler, getCookie } from "h3";
|
|
3
3
|
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
4
4
|
export function requireAuth(handler, options) {
|
|
@@ -40,7 +40,7 @@ export function requireAuth(handler, options) {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
try {
|
|
43
|
-
const payload = await jwtVerify(token, createRemoteJWKSet(new URL("
|
|
43
|
+
const payload = await jwtVerify(token, createRemoteJWKSet(new URL("/api/auth/jwks", apiUrl)), {
|
|
44
44
|
issuer: apiUrl,
|
|
45
45
|
audience: applicationId,
|
|
46
46
|
algorithms: ["RS256"]
|
package/dist/runtime/shared.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AuthClient } from '@meistrari/auth-core';
|
|
2
|
+
export declare function createNuxtAuthClient(apiUrl: string, getAuthToken: () => string | null, getRefreshToken?: () => string | null): AuthClient;
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
"./server/middleware/auth": {
|
|
11
|
-
"types": "./dist/runtime/server/middleware/auth.d.ts",
|
|
12
|
-
"import": "./dist/runtime/server/middleware/auth.js"
|
|
13
|
-
},
|
|
14
|
-
"./core": {
|
|
15
|
-
"types": "./dist/core.d.mts",
|
|
16
|
-
"import": "./dist/core.mjs"
|
|
17
|
-
}
|
|
2
|
+
"name": "@meistrari/auth-nuxt",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/types.d.mts",
|
|
8
|
+
"import": "./dist/module.mjs"
|
|
18
9
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
".": [
|
|
23
|
-
"./dist/types.d.mts"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
10
|
+
"./server/middleware/auth": {
|
|
11
|
+
"types": "./dist/runtime/server/middleware/auth.d.ts",
|
|
12
|
+
"import": "./dist/runtime/server/middleware/auth.js"
|
|
26
13
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"nuxt": "^3.0.0 || ^4.0.0",
|
|
39
|
-
"vue": "^3.0.0"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@nuxt/devtools": "2.6.3",
|
|
43
|
-
"@nuxt/eslint-config": "1.9.0",
|
|
44
|
-
"@nuxt/kit": "4.0.3",
|
|
45
|
-
"@nuxt/module-builder": "1.0.2",
|
|
46
|
-
"@nuxt/schema": "4.0.3",
|
|
47
|
-
"@nuxt/test-utils": "3.19.2",
|
|
48
|
-
"@types/node": "latest",
|
|
49
|
-
"changelogen": "0.6.2",
|
|
50
|
-
"nuxt": "4.0.3",
|
|
51
|
-
"typescript": "5.9.2",
|
|
52
|
-
"unbuild": "3.6.1",
|
|
53
|
-
"vitest": "3.2.4",
|
|
54
|
-
"vue-tsc": "3.0.6"
|
|
14
|
+
"./core": {
|
|
15
|
+
"types": "./dist/core.d.mts",
|
|
16
|
+
"import": "./dist/core.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.mjs",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
".": [
|
|
23
|
+
"./dist/types.d.mts"
|
|
24
|
+
]
|
|
55
25
|
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@meistrari/auth-core": "1.7.0",
|
|
35
|
+
"jose": "6.1.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"nuxt": "^3.0.0 || ^4.0.0",
|
|
39
|
+
"vue": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@nuxt/devtools": "2.6.3",
|
|
43
|
+
"@nuxt/eslint-config": "1.9.0",
|
|
44
|
+
"@nuxt/kit": "4.0.3",
|
|
45
|
+
"@nuxt/module-builder": "1.0.2",
|
|
46
|
+
"@nuxt/schema": "4.0.3",
|
|
47
|
+
"@nuxt/test-utils": "3.19.2",
|
|
48
|
+
"@types/node": "latest",
|
|
49
|
+
"changelogen": "0.6.2",
|
|
50
|
+
"nuxt": "4.0.3",
|
|
51
|
+
"typescript": "5.9.2",
|
|
52
|
+
"unbuild": "3.6.1",
|
|
53
|
+
"vitest": "3.2.4",
|
|
54
|
+
"vue-tsc": "3.0.6"
|
|
55
|
+
}
|
|
56
56
|
}
|