@meistrari/auth-nuxt 3.4.1 → 3.5.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
|
@@ -6,10 +6,14 @@ import type { FullOrganization, User } from '@meistrari/auth-core';
|
|
|
6
6
|
* Provides methods to:
|
|
7
7
|
* - Initiate OAuth login flow with PKCE
|
|
8
8
|
* - Exchange authorization codes for tokens
|
|
9
|
-
* - Automatically refresh access tokens
|
|
10
9
|
* - Manage user session state
|
|
11
10
|
* - Handle logout
|
|
12
11
|
*
|
|
12
|
+
* Session restoration and background token refresh are handled automatically
|
|
13
|
+
* by the SDK's Nuxt plugin — consumers do not need to call any "init" function
|
|
14
|
+
* on app startup or after the OAuth callback. Just read `user` / `activeOrganization`
|
|
15
|
+
* from the returned state.
|
|
16
|
+
*
|
|
13
17
|
* @returns An object containing authentication state and methods
|
|
14
18
|
* @throws {Error} If auth dashboard URL is not configured
|
|
15
19
|
*
|
|
@@ -18,15 +22,9 @@ import type { FullOrganization, User } from '@meistrari/auth-core';
|
|
|
18
22
|
* const auth = useTelaApplicationAuth()
|
|
19
23
|
*
|
|
20
24
|
* // Initiate login
|
|
21
|
-
* await auth.login(
|
|
22
|
-
* applicationId: 'app-123',
|
|
23
|
-
* redirectUri: 'https://example.com/callback'
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* // Initialize session (handles OAuth callback and token refresh)
|
|
27
|
-
* await auth.initSession()
|
|
25
|
+
* await auth.login()
|
|
28
26
|
*
|
|
29
|
-
* // Access user state
|
|
27
|
+
* // Access user state (hydrated automatically by the SDK plugin)
|
|
30
28
|
* console.log(auth.user.value)
|
|
31
29
|
* console.log(auth.activeOrganization.value)
|
|
32
30
|
*
|
|
@@ -104,6 +104,13 @@ export function useTelaApplicationAuth() {
|
|
|
104
104
|
...state,
|
|
105
105
|
login,
|
|
106
106
|
logout,
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated The SDK's Nuxt plugin handles session restoration and background
|
|
109
|
+
* token refresh automatically. On app startup it hydrates `user` and
|
|
110
|
+
* `activeOrganization` via `/auth/whoami` (client) or `whoAmI` (server) and
|
|
111
|
+
* schedules refreshes ahead of access-token expiry. Calling this function
|
|
112
|
+
* is redundant in normal usage and will be removed in a future release.
|
|
113
|
+
*/
|
|
107
114
|
initSession,
|
|
108
115
|
getAvailableOrganizations,
|
|
109
116
|
switchOrganization,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useCookie, useRuntimeConfig } from "#app";
|
|
1
|
+
import { defineNuxtPlugin, navigateTo, useCookie, useRoute, useRuntimeConfig } from "#app";
|
|
2
2
|
import { isTokenExpired } from "@meistrari/auth-core";
|
|
3
3
|
import { useTelaApplicationAuth } from "../composables/application-auth.js";
|
|
4
4
|
import { useApplicationSessionState } from "../composables/state.js";
|
|
@@ -16,7 +16,11 @@ export default defineNuxtPlugin({
|
|
|
16
16
|
async setup() {
|
|
17
17
|
const appConfig = useRuntimeConfig().public.telaAuth;
|
|
18
18
|
const state = useApplicationSessionState();
|
|
19
|
-
const {
|
|
19
|
+
const { logout: sdkLogout } = useTelaApplicationAuth();
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const loginPath = appConfig.application?.loginPath ?? "/login";
|
|
22
|
+
const unauthorizedPath = appConfig.application?.unauthorizedPath ?? "/unauthorized";
|
|
23
|
+
const exemptPaths = [loginPath, unauthorizedPath];
|
|
20
24
|
const accessTokenCookie = useCookie("tela-access-token", {
|
|
21
25
|
secure: !import.meta.dev,
|
|
22
26
|
sameSite: "lax",
|
|
@@ -55,7 +59,13 @@ export default defineNuxtPlugin({
|
|
|
55
59
|
} catch {
|
|
56
60
|
await sdkLogout();
|
|
57
61
|
if (import.meta.client) {
|
|
58
|
-
|
|
62
|
+
const currentPath = decodeURI(route.path);
|
|
63
|
+
if (!exemptPaths.includes(currentPath)) {
|
|
64
|
+
await navigateTo({
|
|
65
|
+
path: loginPath,
|
|
66
|
+
query: { returnTo: route.fullPath }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
} finally {
|
|
61
71
|
isRefreshing = false;
|
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
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
|
-
"./server/middleware/application-auth": {
|
|
15
|
-
"types": "./dist/runtime/server/middleware/application-auth.d.ts",
|
|
16
|
-
"import": "./dist/runtime/server/middleware/application-auth.js"
|
|
17
|
-
},
|
|
18
|
-
"./core": {
|
|
19
|
-
"types": "./dist/core.d.mts",
|
|
20
|
-
"import": "./dist/core.mjs"
|
|
21
|
-
}
|
|
2
|
+
"name": "@meistrari/auth-nuxt",
|
|
3
|
+
"version": "3.5.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/types.d.mts",
|
|
8
|
+
"import": "./dist/module.mjs"
|
|
22
9
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
".": [
|
|
27
|
-
"./dist/types.d.mts"
|
|
28
|
-
]
|
|
29
|
-
}
|
|
10
|
+
"./server/middleware/auth": {
|
|
11
|
+
"types": "./dist/runtime/server/middleware/auth.d.ts",
|
|
12
|
+
"import": "./dist/runtime/server/middleware/auth.js"
|
|
30
13
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
|
|
36
|
-
"docs": "nuxt-module-build prepare && typedoc"
|
|
14
|
+
"./server/middleware/application-auth": {
|
|
15
|
+
"types": "./dist/runtime/server/middleware/application-auth.d.ts",
|
|
16
|
+
"import": "./dist/runtime/server/middleware/application-auth.js"
|
|
37
17
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"@nuxt/kit": "4.0.3",
|
|
50
|
-
"@nuxt/module-builder": "1.0.2",
|
|
51
|
-
"@nuxt/schema": "4.0.3",
|
|
52
|
-
"@nuxt/test-utils": "3.19.2",
|
|
53
|
-
"@types/node": "latest",
|
|
54
|
-
"changelogen": "0.6.2",
|
|
55
|
-
"nuxt": "4.0.3",
|
|
56
|
-
"typescript": "5.9.2",
|
|
57
|
-
"unbuild": "3.6.1",
|
|
58
|
-
"typedoc": "0.28.18",
|
|
59
|
-
"typedoc-plugin-markdown": "4.11.0",
|
|
60
|
-
"vitest": "3.2.4",
|
|
61
|
-
"vue-tsc": "3.0.6"
|
|
18
|
+
"./core": {
|
|
19
|
+
"types": "./dist/core.d.mts",
|
|
20
|
+
"import": "./dist/core.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/module.mjs",
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
".": [
|
|
27
|
+
"./dist/types.d.mts"
|
|
28
|
+
]
|
|
62
29
|
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
|
|
36
|
+
"docs": "nuxt-module-build prepare && typedoc"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@meistrari/auth-core": "1.16.0",
|
|
40
|
+
"jose": "6.1.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"nuxt": "^3.0.0 || ^4.0.0",
|
|
44
|
+
"vue": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@nuxt/devtools": "2.6.3",
|
|
48
|
+
"@nuxt/eslint-config": "1.9.0",
|
|
49
|
+
"@nuxt/kit": "4.0.3",
|
|
50
|
+
"@nuxt/module-builder": "1.0.2",
|
|
51
|
+
"@nuxt/schema": "4.0.3",
|
|
52
|
+
"@nuxt/test-utils": "3.19.2",
|
|
53
|
+
"@types/node": "latest",
|
|
54
|
+
"changelogen": "0.6.2",
|
|
55
|
+
"nuxt": "4.0.3",
|
|
56
|
+
"typescript": "5.9.2",
|
|
57
|
+
"unbuild": "3.6.1",
|
|
58
|
+
"typedoc": "0.28.18",
|
|
59
|
+
"typedoc-plugin-markdown": "4.11.0",
|
|
60
|
+
"vitest": "3.2.4",
|
|
61
|
+
"vue-tsc": "3.0.6"
|
|
62
|
+
}
|
|
63
63
|
}
|