@lenne.tech/nuxt-extensions 1.2.9 → 1.2.12
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.d.mts +1 -1
- package/dist/module.mjs +22 -2
- package/dist/runtime/composables/auth/use-system-setup.d.ts +35 -0
- package/dist/runtime/composables/auth/use-system-setup.js +43 -0
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/lib/auth-client.d.ts +15 -15
- package/dist/runtime/lib/auth-client.js +1 -0
- package/dist/runtime/middleware/setup.d.ts +12 -0
- package/dist/runtime/middleware/setup.js +21 -0
- package/dist/runtime/plugins/auth-interceptor.client.js +2 -1
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/types/module.d.ts +12 -0
- package/dist/types.d.mts +1 -1
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
import { LtExtensionsModuleOptions } from '../dist/runtime/types/index.js';
|
|
3
3
|
export { LtAuthClientConfig, LtAuthMode, LtAuthResponse, LtAuthState, LtPasskeyAuthResult, LtPasskeyRegisterResult, LtUser, UseLtAuthReturn } from '../dist/runtime/types/auth.js';
|
|
4
4
|
export { LtFileInfo, LtUploadItem, LtUploadOptions, LtUploadProgress, LtUploadStatus, UseLtFileReturn, UseLtTusUploadReturn } from '../dist/runtime/types/upload.js';
|
|
5
|
-
export { LtAuthModuleOptions, LtErrorTranslationModuleOptions, LtExtensionsModuleOptions, LtExtensionsPublicRuntimeConfig, LtI18nModuleOptions, LtTusModuleOptions } from '../dist/runtime/types/module.js';
|
|
5
|
+
export { LtAuthModuleOptions, LtErrorTranslationModuleOptions, LtExtensionsModuleOptions, LtExtensionsPublicRuntimeConfig, LtI18nModuleOptions, LtSystemSetupModuleOptions, LtTusModuleOptions } from '../dist/runtime/types/module.js';
|
|
6
6
|
export { LtErrorTranslationResponse, LtParsedError, UseLtErrorTranslationReturn } from '../dist/runtime/types/error.js';
|
|
7
7
|
|
|
8
8
|
declare const name = "@lenne.tech/nuxt-extensions";
|
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addImports, addComponent, addPlugin } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addImports, addComponent, addPlugin, addRouteMiddleware } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const name = "@lenne.tech/nuxt-extensions";
|
|
4
4
|
const version = "1.0.0";
|
|
@@ -16,6 +16,10 @@ const defaultOptions = {
|
|
|
16
16
|
publicPaths: []
|
|
17
17
|
},
|
|
18
18
|
loginPath: "/auth/login",
|
|
19
|
+
systemSetup: {
|
|
20
|
+
enabled: false,
|
|
21
|
+
setupPath: "/auth/setup"
|
|
22
|
+
},
|
|
19
23
|
twoFactorRedirectPath: "/auth/2fa"
|
|
20
24
|
},
|
|
21
25
|
errorTranslation: {
|
|
@@ -41,7 +45,11 @@ const module$1 = defineNuxtModule({
|
|
|
41
45
|
async setup(options, nuxt) {
|
|
42
46
|
const { resolve } = createResolver(import.meta.url);
|
|
43
47
|
const resolvedOptions = {
|
|
44
|
-
auth: {
|
|
48
|
+
auth: {
|
|
49
|
+
...defaultOptions.auth,
|
|
50
|
+
...options.auth,
|
|
51
|
+
systemSetup: { ...defaultOptions.auth.systemSetup, ...options.auth?.systemSetup }
|
|
52
|
+
},
|
|
45
53
|
errorTranslation: { ...defaultOptions.errorTranslation, ...options.errorTranslation },
|
|
46
54
|
i18n: { ...defaultOptions.i18n, ...options.i18n },
|
|
47
55
|
tus: { ...defaultOptions.tus, ...options.tus }
|
|
@@ -59,6 +67,10 @@ const module$1 = defineNuxtModule({
|
|
|
59
67
|
publicPaths: resolvedOptions.auth?.interceptor?.publicPaths || []
|
|
60
68
|
},
|
|
61
69
|
loginPath: resolvedOptions.auth?.loginPath || "/auth/login",
|
|
70
|
+
systemSetup: {
|
|
71
|
+
enabled: resolvedOptions.auth?.systemSetup?.enabled ?? false,
|
|
72
|
+
setupPath: resolvedOptions.auth?.systemSetup?.setupPath || "/auth/setup"
|
|
73
|
+
},
|
|
62
74
|
twoFactorRedirectPath: resolvedOptions.auth?.twoFactorRedirectPath || "/auth/2fa"
|
|
63
75
|
},
|
|
64
76
|
errorTranslation: {
|
|
@@ -82,6 +94,7 @@ const module$1 = defineNuxtModule({
|
|
|
82
94
|
{ name: "useLtFile", from: resolve("./runtime/composables/use-lt-file") },
|
|
83
95
|
{ name: "useLtTusUpload", from: resolve("./runtime/composables/use-lt-tus-upload") },
|
|
84
96
|
{ name: "useLtShare", from: resolve("./runtime/composables/use-lt-share") },
|
|
97
|
+
{ name: "useSystemSetup", from: resolve("./runtime/composables/auth/use-system-setup") },
|
|
85
98
|
// Utils
|
|
86
99
|
{ name: "ltSha256", from: resolve("./runtime/utils/crypto") },
|
|
87
100
|
{ name: "ltArrayBufferToBase64Url", from: resolve("./runtime/utils/crypto") },
|
|
@@ -119,6 +132,13 @@ const module$1 = defineNuxtModule({
|
|
|
119
132
|
if (resolvedOptions.auth?.enabled && resolvedOptions.auth?.interceptor?.enabled) {
|
|
120
133
|
addPlugin(resolve("./runtime/plugins/auth-interceptor.client"));
|
|
121
134
|
}
|
|
135
|
+
if (resolvedOptions.auth?.systemSetup?.enabled) {
|
|
136
|
+
addRouteMiddleware({
|
|
137
|
+
name: "lt-system-setup",
|
|
138
|
+
path: resolve("./runtime/middleware/setup"),
|
|
139
|
+
global: true
|
|
140
|
+
});
|
|
141
|
+
}
|
|
122
142
|
if (resolvedOptions.errorTranslation?.enabled) {
|
|
123
143
|
addPlugin(resolve("./runtime/plugins/error-translation.client"));
|
|
124
144
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System Setup Composable
|
|
3
|
+
*
|
|
4
|
+
* Checks whether the system needs initial setup (first admin user creation)
|
|
5
|
+
* and provides a method to perform that setup.
|
|
6
|
+
*
|
|
7
|
+
* Uses useState for SSR-compatible state management.
|
|
8
|
+
*/
|
|
9
|
+
import type { ComputedRef } from "vue";
|
|
10
|
+
export interface UseSystemSetupReturn {
|
|
11
|
+
/** Whether the system needs initial setup (null = not checked yet) */
|
|
12
|
+
needsSetup: ComputedRef<boolean | null>;
|
|
13
|
+
/** Check setup status from the backend */
|
|
14
|
+
checkSetupStatus: () => Promise<boolean>;
|
|
15
|
+
/** Initialize the system with the first admin user */
|
|
16
|
+
initSetup: (params: {
|
|
17
|
+
email: string;
|
|
18
|
+
password: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Composable for system setup flow (first admin user creation)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const { needsSetup, checkSetupStatus, initSetup } = useSystemSetup();
|
|
28
|
+
*
|
|
29
|
+
* await checkSetupStatus();
|
|
30
|
+
* if (needsSetup.value) {
|
|
31
|
+
* await initSetup({ email: 'admin@example.com', password: 'secret', name: 'Admin' });
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function useSystemSetup(): UseSystemSetupReturn;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { computed, useRuntimeConfig, useState } from "#imports";
|
|
2
|
+
import { getLtApiBase } from "../../lib/auth-state.js";
|
|
3
|
+
import { ltSha256 } from "../../utils/crypto.js";
|
|
4
|
+
export function useSystemSetup() {
|
|
5
|
+
const runtimeConfig = useRuntimeConfig();
|
|
6
|
+
const needsSetupState = useState("lt-needs-setup", () => null);
|
|
7
|
+
const needsSetup = computed(() => needsSetupState.value);
|
|
8
|
+
async function checkSetupStatus() {
|
|
9
|
+
try {
|
|
10
|
+
let url;
|
|
11
|
+
if (import.meta.server) {
|
|
12
|
+
const apiUrl = runtimeConfig.apiUrl || "http://localhost:3000";
|
|
13
|
+
url = `${apiUrl}/api/system-setup/status`;
|
|
14
|
+
} else {
|
|
15
|
+
url = "/api/system-setup/status";
|
|
16
|
+
}
|
|
17
|
+
const data = await $fetch(url);
|
|
18
|
+
needsSetupState.value = data.needsSetup;
|
|
19
|
+
return data.needsSetup;
|
|
20
|
+
} catch {
|
|
21
|
+
needsSetupState.value = false;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function initSetup(params) {
|
|
26
|
+
const apiBase = getLtApiBase();
|
|
27
|
+
const hashedPassword = await ltSha256(params.password);
|
|
28
|
+
await $fetch(`${apiBase}/system-setup/init`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: {
|
|
31
|
+
email: params.email,
|
|
32
|
+
password: hashedPassword,
|
|
33
|
+
name: params.name
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
needsSetupState.value = false;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
needsSetup,
|
|
40
|
+
checkSetupStatus,
|
|
41
|
+
initSetup
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useLtAuth } from "./auth/use-lt-auth.js";
|
|
2
|
+
export { useSystemSetup } from "./auth/use-system-setup.js";
|
|
2
3
|
export { useLtAuthClient, ltAuthClient } from "./use-lt-auth-client.js";
|
|
3
4
|
export { useLtTusUpload } from "./use-lt-tus-upload.js";
|
|
4
5
|
export { useLtFile } from "./use-lt-file.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useLtAuth } from "./auth/use-lt-auth.js";
|
|
2
|
+
export { useSystemSetup } from "./auth/use-system-setup.js";
|
|
2
3
|
export { useLtAuthClient, ltAuthClient } from "./use-lt-auth-client.js";
|
|
3
4
|
export { useLtTusUpload } from "./use-lt-tus-upload.js";
|
|
4
5
|
export { useLtFile } from "./use-lt-file.js";
|
|
@@ -280,6 +280,21 @@ export declare function createLtAuthClient(config?: LtAuthClientConfig): {
|
|
|
280
280
|
listen: (signal: Omit<string, "$sessionSignal"> | "$sessionSignal", listener: (value: boolean, oldValue?: boolean | undefined) => void) => void;
|
|
281
281
|
atoms: Record<string, import("better-auth/client").WritableAtom<any>>;
|
|
282
282
|
};
|
|
283
|
+
requestPasswordReset: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
284
|
+
email: string;
|
|
285
|
+
redirectTo?: string | undefined;
|
|
286
|
+
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth").Prettify<{
|
|
287
|
+
email: string;
|
|
288
|
+
redirectTo?: string | undefined;
|
|
289
|
+
} & {
|
|
290
|
+
fetchOptions?: FetchOptions | undefined;
|
|
291
|
+
}>, data_1?: FetchOptions | undefined) => Promise<import("better-auth/client").BetterFetchResponse<{
|
|
292
|
+
status: boolean;
|
|
293
|
+
message: string;
|
|
294
|
+
}, {
|
|
295
|
+
code?: string | undefined;
|
|
296
|
+
message?: string | undefined;
|
|
297
|
+
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
283
298
|
/**
|
|
284
299
|
* Change password for an authenticated user (both passwords are hashed)
|
|
285
300
|
*/
|
|
@@ -615,21 +630,6 @@ export declare function createLtAuthClient(config?: LtAuthClientConfig): {
|
|
|
615
630
|
message?: string | undefined;
|
|
616
631
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
617
632
|
};
|
|
618
|
-
requestPasswordReset: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
619
|
-
email: string;
|
|
620
|
-
redirectTo?: string | undefined;
|
|
621
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth").Prettify<{
|
|
622
|
-
email: string;
|
|
623
|
-
redirectTo?: string | undefined;
|
|
624
|
-
} & {
|
|
625
|
-
fetchOptions?: FetchOptions | undefined;
|
|
626
|
-
}>, data_1?: FetchOptions | undefined) => Promise<import("better-auth/client").BetterFetchResponse<{
|
|
627
|
-
status: boolean;
|
|
628
|
-
message: string;
|
|
629
|
-
}, {
|
|
630
|
-
code?: string | undefined;
|
|
631
|
-
message?: string | undefined;
|
|
632
|
-
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
633
633
|
listSessions: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth").Prettify<{
|
|
634
634
|
query?: Record<string, any> | undefined;
|
|
635
635
|
fetchOptions?: FetchOptions | undefined;
|
|
@@ -89,6 +89,7 @@ export function createLtAuthClient(config = {}) {
|
|
|
89
89
|
$Infer: baseClient.$Infer,
|
|
90
90
|
$fetch: baseClient.$fetch,
|
|
91
91
|
$store: baseClient.$store,
|
|
92
|
+
requestPasswordReset: baseClient.requestPasswordReset,
|
|
92
93
|
/**
|
|
93
94
|
* Change password for an authenticated user (both passwords are hashed)
|
|
94
95
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System Setup Middleware
|
|
3
|
+
*
|
|
4
|
+
* Global middleware that redirects to the setup page when the system
|
|
5
|
+
* needs initial setup (no admin user exists yet).
|
|
6
|
+
*
|
|
7
|
+
* - needsSetup === null -> calls checkSetupStatus()
|
|
8
|
+
* - needsSetup === true AND route != setupPath -> redirect to setupPath
|
|
9
|
+
* - needsSetup === false AND route === setupPath -> redirect to loginPath
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: import("nuxt/app").RouteMiddleware;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineNuxtRouteMiddleware, navigateTo, useRuntimeConfig } from "#imports";
|
|
2
|
+
import { useSystemSetup } from "../composables/auth/use-system-setup.js";
|
|
3
|
+
export default defineNuxtRouteMiddleware(async (to) => {
|
|
4
|
+
const runtimeConfig = useRuntimeConfig();
|
|
5
|
+
const authConfig = runtimeConfig.public?.ltExtensions?.auth;
|
|
6
|
+
const setupPath = authConfig?.systemSetup?.setupPath || "/auth/setup";
|
|
7
|
+
const loginPath = authConfig?.loginPath || "/auth/login";
|
|
8
|
+
const { needsSetup, checkSetupStatus } = useSystemSetup();
|
|
9
|
+
try {
|
|
10
|
+
if (needsSetup.value === null) {
|
|
11
|
+
await checkSetupStatus();
|
|
12
|
+
}
|
|
13
|
+
if (needsSetup.value === true && to.path !== setupPath) {
|
|
14
|
+
return navigateTo(setupPath);
|
|
15
|
+
}
|
|
16
|
+
if (needsSetup.value === false && to.path === setupPath) {
|
|
17
|
+
return navigateTo(loginPath);
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -17,7 +17,8 @@ export default (nuxtApp) => {
|
|
|
17
17
|
"/auth/register",
|
|
18
18
|
"/auth/forgot-password",
|
|
19
19
|
"/auth/reset-password",
|
|
20
|
-
"/auth/2fa"
|
|
20
|
+
"/auth/2fa",
|
|
21
|
+
"/auth/setup"
|
|
21
22
|
];
|
|
22
23
|
const publicAuthPaths = [.../* @__PURE__ */ new Set([...defaultPublicPaths, ...configuredPublicPaths])];
|
|
23
24
|
function isPublicAuthRoute() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { LtAuthClientConfig, LtAuthMode, LtAuthResponse, LtAuthState, LtPasskeyAuthResult, LtPasskeyRegisterResult, LtUser, UseLtAuthReturn, } from "./auth.js";
|
|
2
2
|
export type { LtFileInfo, LtUploadItem, LtUploadOptions, LtUploadProgress, LtUploadStatus, UseLtFileReturn, UseLtTusUploadReturn, } from "./upload.js";
|
|
3
|
-
export type { LtAuthModuleOptions, LtErrorTranslationModuleOptions, LtExtensionsModuleOptions, LtExtensionsPublicRuntimeConfig, LtI18nModuleOptions, LtTusModuleOptions, } from "./module.js";
|
|
3
|
+
export type { LtAuthModuleOptions, LtErrorTranslationModuleOptions, LtExtensionsModuleOptions, LtExtensionsPublicRuntimeConfig, LtI18nModuleOptions, LtSystemSetupModuleOptions, LtTusModuleOptions, } from "./module.js";
|
|
4
4
|
export type { LtErrorTranslationResponse, LtParsedError, UseLtErrorTranslationReturn, } from "./error.js";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth module configuration options
|
|
3
3
|
*/
|
|
4
|
+
export interface LtSystemSetupModuleOptions {
|
|
5
|
+
/** Enable system setup flow (default: false) */
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
/** Path to the setup page (default: '/auth/setup') */
|
|
8
|
+
setupPath?: string;
|
|
9
|
+
}
|
|
4
10
|
export interface LtAuthModuleOptions {
|
|
5
11
|
/** Auth API base path (default: '/iam' - must match nest-server betterAuth.basePath) */
|
|
6
12
|
basePath?: string;
|
|
@@ -23,6 +29,8 @@ export interface LtAuthModuleOptions {
|
|
|
23
29
|
};
|
|
24
30
|
/** Login page path for redirects (default: '/auth/login') */
|
|
25
31
|
loginPath?: string;
|
|
32
|
+
/** System setup configuration */
|
|
33
|
+
systemSetup?: LtSystemSetupModuleOptions;
|
|
26
34
|
/** 2FA redirect path (default: '/auth/2fa') */
|
|
27
35
|
twoFactorRedirectPath?: string;
|
|
28
36
|
}
|
|
@@ -81,6 +89,10 @@ export interface LtExtensionsPublicRuntimeConfig {
|
|
|
81
89
|
publicPaths: string[];
|
|
82
90
|
};
|
|
83
91
|
loginPath: string;
|
|
92
|
+
systemSetup: {
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
setupPath: string;
|
|
95
|
+
};
|
|
84
96
|
twoFactorRedirectPath: string;
|
|
85
97
|
};
|
|
86
98
|
errorTranslation: {
|
package/dist/types.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ export { type LtAuthClientConfig, type LtAuthMode, type LtAuthResponse, type LtA
|
|
|
8
8
|
|
|
9
9
|
export { type LtFileInfo, type LtUploadItem, type LtUploadOptions, type LtUploadProgress, type LtUploadStatus, type UseLtFileReturn, type UseLtTusUploadReturn } from '../dist/runtime/types/upload.js'
|
|
10
10
|
|
|
11
|
-
export { type LtAuthModuleOptions, type LtErrorTranslationModuleOptions, type LtExtensionsModuleOptions, type LtExtensionsPublicRuntimeConfig, type LtI18nModuleOptions, type LtTusModuleOptions } from '../dist/runtime/types/module.js'
|
|
11
|
+
export { type LtAuthModuleOptions, type LtErrorTranslationModuleOptions, type LtExtensionsModuleOptions, type LtExtensionsPublicRuntimeConfig, type LtI18nModuleOptions, type LtSystemSetupModuleOptions, type LtTusModuleOptions } from '../dist/runtime/types/module.js'
|
|
12
12
|
|
|
13
13
|
export { type LtErrorTranslationResponse, type LtParsedError, type UseLtErrorTranslationReturn } from '../dist/runtime/types/error.js'
|
|
14
14
|
|