@lenne.tech/nuxt-extensions 1.1.0 → 1.2.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/README.md +44 -0
- package/dist/runtime/composables/auth/use-lt-auth.js +18 -3
- package/dist/runtime/lib/auth-client.d.ts +31 -0
- package/dist/runtime/lib/auth-client.js +14 -1
- package/dist/runtime/lib/index.d.ts +1 -1
- package/dist/runtime/lib/index.js +6 -1
- package/dist/runtime/types/auth.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,6 +127,49 @@ async function handlePasskeyLogin() {
|
|
|
127
127
|
</template>
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
### Custom Better Auth Plugins
|
|
131
|
+
|
|
132
|
+
You can extend the auth client with additional [Better Auth plugins](https://www.better-auth.com/docs/plugins):
|
|
133
|
+
|
|
134
|
+
**Option 1: Plugin Registration (recommended)**
|
|
135
|
+
|
|
136
|
+
Create a Nuxt plugin to register plugins before the auth client is initialized:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// plugins/auth-plugins.client.ts
|
|
140
|
+
import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions';
|
|
141
|
+
import { organizationClient, magicLinkClient } from 'better-auth/client/plugins';
|
|
142
|
+
|
|
143
|
+
export default defineNuxtPlugin(() => {
|
|
144
|
+
registerLtAuthPlugins([
|
|
145
|
+
organizationClient(),
|
|
146
|
+
magicLinkClient(),
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Option 2: Direct Factory Usage**
|
|
152
|
+
|
|
153
|
+
For full control, create the auth client directly with your plugins:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { createLtAuthClient } from '@lenne.tech/nuxt-extensions';
|
|
157
|
+
import { organizationClient } from 'better-auth/client/plugins';
|
|
158
|
+
|
|
159
|
+
const authClient = createLtAuthClient({
|
|
160
|
+
plugins: [organizationClient()],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Use authClient.organization.* methods
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Available Better Auth Plugins:**
|
|
167
|
+
- `organizationClient` - Organization/team management
|
|
168
|
+
- `magicLinkClient` - Passwordless email login
|
|
169
|
+
- `oneTapClient` - Google One Tap login
|
|
170
|
+
- `anonymousClient` - Anonymous/guest sessions
|
|
171
|
+
- See [Better Auth Plugins](https://www.better-auth.com/docs/plugins) for full list
|
|
172
|
+
|
|
130
173
|
### TUS File Upload
|
|
131
174
|
|
|
132
175
|
```vue
|
|
@@ -276,6 +319,7 @@ The package works **with or without** `@nuxtjs/i18n`:
|
|
|
276
319
|
| `ltArrayBufferToBase64Url()` | ArrayBuffer to base64url conversion |
|
|
277
320
|
| `ltBase64UrlToUint8Array()` | Base64url to Uint8Array conversion |
|
|
278
321
|
| `createLtAuthClient()` | Auth client factory for custom configuration |
|
|
322
|
+
| `registerLtAuthPlugins()` | Register custom Better Auth plugins |
|
|
279
323
|
|
|
280
324
|
## Related Projects
|
|
281
325
|
|
|
@@ -401,15 +401,30 @@ export function useLtAuth() {
|
|
|
401
401
|
}
|
|
402
402
|
return { success: true, passkey: result };
|
|
403
403
|
} catch (err) {
|
|
404
|
-
if (err instanceof Error
|
|
404
|
+
if (err instanceof Error) {
|
|
405
|
+
if (err.name === "NotAllowedError") {
|
|
406
|
+
return {
|
|
407
|
+
success: false,
|
|
408
|
+
error: t("lt.auth.passkeyCreationAborted", "Passkey-Erstellung wurde abgebrochen")
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (err.name === "InvalidStateError" || err.message.includes("already registered") || err.message.includes("credentials already registered")) {
|
|
412
|
+
return {
|
|
413
|
+
success: false,
|
|
414
|
+
error: t(
|
|
415
|
+
"lt.auth.passkeyAlreadyRegistered",
|
|
416
|
+
"Du hast bereits einen Passkey f\xFCr diese Website registriert. L\xF6sche ihn zuerst oder verwende einen anderen Authenticator."
|
|
417
|
+
)
|
|
418
|
+
};
|
|
419
|
+
}
|
|
405
420
|
return {
|
|
406
421
|
success: false,
|
|
407
|
-
error:
|
|
422
|
+
error: err.message
|
|
408
423
|
};
|
|
409
424
|
}
|
|
410
425
|
return {
|
|
411
426
|
success: false,
|
|
412
|
-
error:
|
|
427
|
+
error: t("lt.auth.passkeyRegisterFailed", "Passkey-Registrierung fehlgeschlagen")
|
|
413
428
|
};
|
|
414
429
|
} finally {
|
|
415
430
|
isLoading.value = false;
|
|
@@ -8,6 +8,37 @@
|
|
|
8
8
|
* plain text password transmission over the network.
|
|
9
9
|
*/
|
|
10
10
|
import type { LtAuthClientConfig } from "../types/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Register additional Better Auth plugins before auth client initialization.
|
|
13
|
+
*
|
|
14
|
+
* Call this in a Nuxt plugin (client-side) or in app.vue setup before
|
|
15
|
+
* the auth client is used.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // plugins/auth-plugins.client.ts
|
|
20
|
+
* import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions';
|
|
21
|
+
* import { organizationClient, magicLinkClient } from 'better-auth/client/plugins';
|
|
22
|
+
*
|
|
23
|
+
* export default defineNuxtPlugin(() => {
|
|
24
|
+
* registerLtAuthPlugins([
|
|
25
|
+
* organizationClient(),
|
|
26
|
+
* magicLinkClient(),
|
|
27
|
+
* ]);
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function registerLtAuthPlugins(plugins: unknown[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get the current plugin registry.
|
|
34
|
+
* Used internally by createLtAuthClient.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLtAuthPluginRegistry(): unknown[];
|
|
37
|
+
/**
|
|
38
|
+
* Clear the plugin registry.
|
|
39
|
+
* Useful for testing or resetting state.
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearLtAuthPluginRegistry(): void;
|
|
11
42
|
/**
|
|
12
43
|
* Creates a configured Better-Auth client with password hashing
|
|
13
44
|
*
|
|
@@ -4,6 +4,16 @@ import { createAuthClient } from "better-auth/vue";
|
|
|
4
4
|
import { navigateTo } from "#imports";
|
|
5
5
|
import { ltSha256 } from "../utils/crypto.js";
|
|
6
6
|
import { createLtAuthFetch, isLtDevMode } from "./auth-state.js";
|
|
7
|
+
let _ltAuthPluginRegistry = [];
|
|
8
|
+
export function registerLtAuthPlugins(plugins) {
|
|
9
|
+
_ltAuthPluginRegistry = [..._ltAuthPluginRegistry, ...plugins];
|
|
10
|
+
}
|
|
11
|
+
export function getLtAuthPluginRegistry() {
|
|
12
|
+
return _ltAuthPluginRegistry;
|
|
13
|
+
}
|
|
14
|
+
export function clearLtAuthPluginRegistry() {
|
|
15
|
+
_ltAuthPluginRegistry = [];
|
|
16
|
+
}
|
|
7
17
|
export function createLtAuthClient(config = {}) {
|
|
8
18
|
const isDev = isLtDevMode();
|
|
9
19
|
const defaultBaseURL = isDev ? "" : import.meta.env?.VITE_API_URL || process.env.API_URL || "http://localhost:3000";
|
|
@@ -14,7 +24,8 @@ export function createLtAuthClient(config = {}) {
|
|
|
14
24
|
twoFactorRedirectPath = "/auth/2fa",
|
|
15
25
|
enableAdmin = true,
|
|
16
26
|
enableTwoFactor = true,
|
|
17
|
-
enablePasskey = true
|
|
27
|
+
enablePasskey = true,
|
|
28
|
+
plugins: externalPlugins = []
|
|
18
29
|
} = config;
|
|
19
30
|
const plugins = [];
|
|
20
31
|
if (enableAdmin) {
|
|
@@ -32,6 +43,8 @@ export function createLtAuthClient(config = {}) {
|
|
|
32
43
|
if (enablePasskey) {
|
|
33
44
|
plugins.push(passkeyClient());
|
|
34
45
|
}
|
|
46
|
+
plugins.push(...externalPlugins);
|
|
47
|
+
plugins.push(..._ltAuthPluginRegistry);
|
|
35
48
|
const authFetch = createLtAuthFetch(basePath.replace("/api", ""));
|
|
36
49
|
const baseClient = createAuthClient({
|
|
37
50
|
basePath,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { attemptLtJwtSwitch, createLtAuthFetch, getLtApiBase, getLtAuthMode, getLtJwtToken, isLtAuthenticated, ltAuthFetch, setLtAuthMode, setLtJwtToken, } from "./auth-state.js";
|
|
2
|
-
export { createLtAuthClient, type LtAuthClient } from "./auth-client.js";
|
|
2
|
+
export { clearLtAuthPluginRegistry, createLtAuthClient, getLtAuthPluginRegistry, registerLtAuthPlugins, type LtAuthClient, } from "./auth-client.js";
|
|
@@ -9,4 +9,9 @@ export {
|
|
|
9
9
|
setLtAuthMode,
|
|
10
10
|
setLtJwtToken
|
|
11
11
|
} from "./auth-state.js";
|
|
12
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
clearLtAuthPluginRegistry,
|
|
14
|
+
createLtAuthClient,
|
|
15
|
+
getLtAuthPluginRegistry,
|
|
16
|
+
registerLtAuthPlugins
|
|
17
|
+
} from "./auth-client.js";
|
|
@@ -45,6 +45,8 @@ export interface LtAuthClientConfig {
|
|
|
45
45
|
enableTwoFactor?: boolean;
|
|
46
46
|
/** 2FA redirect path (default: '/auth/2fa') */
|
|
47
47
|
twoFactorRedirectPath?: string;
|
|
48
|
+
/** Additional Better Auth client plugins (e.g., organizationClient, magicLinkClient) */
|
|
49
|
+
plugins?: unknown[];
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
52
|
* Normalized response type for Better-Auth operations
|