@frigear-nu/users 0.0.0-stage โ†’ 1.0.3

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.
Files changed (58) hide show
  1. package/README.md +179 -2
  2. package/dist/module.d.mts +72 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +207 -0
  5. package/dist/runtime/app/composables/useAuthManifest.d.ts +5 -0
  6. package/dist/runtime/app/composables/useAuthManifest.js +7 -0
  7. package/dist/runtime/app/composables/useUserLogin.d.ts +12 -0
  8. package/dist/runtime/app/composables/useUserLogin.js +26 -0
  9. package/dist/runtime/app/composables/useUserPasskeys.d.ts +7 -0
  10. package/dist/runtime/app/composables/useUserPasskeys.js +22 -0
  11. package/dist/runtime/app/composables/useUserPasswordReset.d.ts +13 -0
  12. package/dist/runtime/app/composables/useUserPasswordReset.js +32 -0
  13. package/dist/runtime/app/composables/useUserRegistration.d.ts +10 -0
  14. package/dist/runtime/app/composables/useUserRegistration.js +20 -0
  15. package/dist/runtime/app/pages/login.d.vue.ts +3 -0
  16. package/dist/runtime/app/pages/login.vue +68 -0
  17. package/dist/runtime/app/pages/login.vue.d.ts +3 -0
  18. package/dist/runtime/app/pages/register.d.vue.ts +3 -0
  19. package/dist/runtime/app/pages/register.vue +40 -0
  20. package/dist/runtime/app/pages/register.vue.d.ts +3 -0
  21. package/dist/runtime/app/utils/oauth-providers.d.ts +13 -0
  22. package/dist/runtime/app/utils/oauth-providers.js +4 -0
  23. package/dist/runtime/db/schema.sqlite.d.ts +339 -0
  24. package/dist/runtime/db/schema.sqlite.js +29 -0
  25. package/dist/runtime/i18n/lang/da.json +88 -0
  26. package/dist/runtime/i18n/lang/en.json +88 -0
  27. package/dist/runtime/menus.d.ts +2 -0
  28. package/dist/runtime/menus.js +12 -0
  29. package/dist/runtime/server/routes/auth/forgot-password.post.d.ts +2 -0
  30. package/dist/runtime/server/routes/auth/forgot-password.post.js +19 -0
  31. package/dist/runtime/server/routes/auth/github.get.d.ts +2 -0
  32. package/dist/runtime/server/routes/auth/github.get.js +7 -0
  33. package/dist/runtime/server/routes/auth/google.get.d.ts +2 -0
  34. package/dist/runtime/server/routes/auth/google.get.js +6 -0
  35. package/dist/runtime/server/routes/auth/login.post.d.ts +2 -0
  36. package/dist/runtime/server/routes/auth/login.post.js +15 -0
  37. package/dist/runtime/server/routes/auth/logout.get.d.ts +2 -0
  38. package/dist/runtime/server/routes/auth/logout.get.js +4 -0
  39. package/dist/runtime/server/routes/auth/register.post.d.ts +2 -0
  40. package/dist/runtime/server/routes/auth/register.post.js +18 -0
  41. package/dist/runtime/server/routes/auth/reset-password.post.d.ts +2 -0
  42. package/dist/runtime/server/routes/auth/reset-password.post.js +29 -0
  43. package/dist/runtime/server/routes/auth/webauthn/authenticate.post.d.ts +2 -0
  44. package/dist/runtime/server/routes/auth/webauthn/authenticate.post.js +34 -0
  45. package/dist/runtime/server/routes/auth/webauthn/credentials/[id].delete.d.ts +2 -0
  46. package/dist/runtime/server/routes/auth/webauthn/credentials/[id].delete.js +9 -0
  47. package/dist/runtime/server/routes/auth/webauthn/credentials/index.get.d.ts +2 -0
  48. package/dist/runtime/server/routes/auth/webauthn/credentials/index.get.js +8 -0
  49. package/dist/runtime/server/routes/auth/webauthn/register.post.d.ts +2 -0
  50. package/dist/runtime/server/routes/auth/webauthn/register.post.js +42 -0
  51. package/dist/runtime/server/utils/oauth.d.ts +8 -0
  52. package/dist/runtime/server/utils/oauth.js +18 -0
  53. package/dist/runtime/server/utils/password-reset.d.ts +22 -0
  54. package/dist/runtime/server/utils/password-reset.js +14 -0
  55. package/dist/runtime/server/utils/session.d.ts +11 -0
  56. package/dist/runtime/server/utils/session.js +5 -0
  57. package/dist/types.d.mts +3 -0
  58. package/package.json +86 -3
package/README.md CHANGED
@@ -1,3 +1,180 @@
1
- # Temporary Holding Version
1
+ # @frigear-nu/users
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![License][license-src]][license-href]
6
+ [![Nuxt][nuxt-src]][nuxt-href]
7
+
8
+ A module for managing the users in the main frigear app. for doing amazing things.
9
+
10
+ ## Features
11
+
12
+ - โ›ฐ Manages users & their schema in teh standard frigear way.
13
+ - ๐Ÿš  Can be extended using other modules or fields on metadata
14
+ - ๐ŸŒฒ Simple to use, supports billing & subscriptions.
15
+ - ๐Ÿ”‘ Email/password login & registration, with an on/off switch.
16
+ - โœ‰๏ธ Forgot/reset password flow, dispatched through a pluggable email driver (`@frigear-nu/notify`) so the module stays dependency-free.
17
+ - ๐Ÿ” Passkey (WebAuthn) registration, authentication & credential management.
18
+ - ๐Ÿชช "Simple" OAuth routes for GitHub & Google, powered by [`nuxt-auth-utils`](https://github.com/atinux/nuxt-auth-utils). Any other provider it supports can be wired up directly in the consuming app.
19
+ - ๐Ÿงฉ Overridable composables (`useUserLogin`, `useUserRegistration`, `useUserPasswordReset`, `useUserPasskeys`) and opt-in login/register pages (built with [`@nuxt/ui`](https://ui.nuxt.com)).
20
+ - ๐Ÿงต Session enrichment: the logged-in user is mapped into the session once, at login/registration time.
21
+
22
+ ## Quick Setup
23
+
24
+ Install the module to your Nuxt application with one command:
25
+
26
+ ```bash
27
+ npx nuxt module add @frigear-nu/users
28
+ ```
29
+
30
+ That's it! You can now use @frigear-nu/users in your Nuxt app โœจ
31
+
32
+ This module requires [`@nuxthub/core`](https://hub.nuxt.com) to be configured in the host app, since it relies on it for
33
+ the `users` (and, when WebAuthn is enabled, `user_credentials`) database table.
34
+
35
+ ## Configuration
36
+
37
+ Configure the module via the `users` key in `nuxt.config.ts`:
38
+
39
+ ```ts
40
+ export default defineNuxtConfig({
41
+ modules: ['@nuxthub/core', '@frigear-nu/users'],
42
+ users: {
43
+ mode: 'server',
44
+ settings: {
45
+ // Enable/disable email + password login & register routes, composables and pages.
46
+ // Defaults to `true`.
47
+ password: true,
48
+ // Enable/disable the "forgot password"/"reset password" routes & composable. Requires
49
+ // `password` to be enabled. Defaults to `true` whenever `password` is enabled.
50
+ passwordReset: true,
51
+ // Enable passkey (WebAuthn) registration/authentication routes, composables and DB table.
52
+ // Requires the optional `@simplewebauthn/browser` and `@simplewebauthn/server` peer deps.
53
+ // Defaults to `false`.
54
+ webAuthn: false,
55
+ // Registers the login/register pages, built with `@nuxt/ui` (an optional peer dependency,
56
+ // required only when a page is enabled). Off by default; set to `true` for the default
57
+ // path (`/login`, `/register`) or a custom path string to opt in.
58
+ pages: {
59
+ login: true,
60
+ register: '/sign-up',
61
+ },
62
+ session: {
63
+ // Path to a function (default export) mapping the raw DB user to the session user shape.
64
+ mapper: '~/server/utils/map-session-user',
65
+ },
66
+ // Registers the "simple" OAuth routes we ship (`/api/auth/github`, `/api/auth/google`).
67
+ // Each provider's client id/secret are read by nuxt-auth-utils itself from the standard
68
+ // `NUXT_OAUTH_<PROVIDER>_CLIENT_ID` / `NUXT_OAUTH_<PROVIDER>_CLIENT_SECRET` env vars.
69
+ // Route registration depends only on these flags. Any other provider supported by
70
+ // nuxt-auth-utils can be added directly in the consuming app.
71
+ oauth: {
72
+ github: true,
73
+ google: true,
74
+ },
75
+ },
76
+ },
77
+ })
78
+ ```
79
+
80
+ The password-reset email is dispatched as an `EmailNotification` through [`@frigear-nu/notify`](../notify), which this module declares as a `moduleDependency` (it's installed automatically - no need to add it to `modules` yourself). Which driver actually delivers it is an app/deployment concern, so it's configured separately, under the `notify` key:
81
+
82
+ ```ts
83
+ export default defineNuxtConfig({
84
+ modules: ['@nuxthub/core', '@frigear-nu/users'],
85
+ notify: {
86
+ email: {
87
+ // Name of a built-in driver (`'log'`, the default - logs instead of sending) or a path to
88
+ // a function (default export) matching the `EmailDriver` signature, for a real provider.
89
+ driver: '~/server/utils/resend-email-driver',
90
+ },
91
+ },
92
+ })
93
+ ```
94
+
95
+ ```ts
96
+ // server/utils/resend-email-driver.ts
97
+ import type { EmailDriver } from '@frigear-nu/notify/types'
98
+
99
+ const sendWithResend: EmailDriver = async (notification) => {
100
+ // ... call your provider's API with notification.to/subject/body/text
101
+ }
102
+
103
+ export default sendWithResend
104
+ ```
105
+
106
+ ### Routes
107
+
108
+ | Route | Enabled by | Description |
109
+ | --- | --- | --- |
110
+ | `POST /api/auth/login` | `settings.password` | Email/password login |
111
+ | `POST /api/auth/register` | `settings.password` | Email/password registration |
112
+ | `POST /api/auth/forgot-password` | `settings.passwordReset` | Request a password reset email for an `email` |
113
+ | `POST /api/auth/reset-password` | `settings.passwordReset` | Reset the password given a reset `code`, `password` & `confirmPassword`, and sign in |
114
+ | `POST /api/auth/webauthn/register` | `settings.webAuthn` | Register a new passkey |
115
+ | `POST /api/auth/webauthn/authenticate` | `settings.webAuthn` | Authenticate with a passkey |
116
+ | `GET /api/auth/webauthn/credentials` | `settings.webAuthn` | List the current user's passkeys |
117
+ | `DELETE /api/auth/webauthn/credentials/:id` | `settings.webAuthn` | Remove one of the current user's passkeys |
118
+ | `GET /api/auth/github`, `/google` | `settings.oauth.<provider>` | "Simple" OAuth login |
119
+
120
+ ### Pages
121
+
122
+ | Page | Enabled by | Description |
123
+ | --- | --- | --- |
124
+ | Login | `settings.pages.login` | Renders a `UAuthForm` with the password fields and/or OAuth provider buttons that are actually enabled |
125
+ | Register | `settings.pages.register` | Renders a `UAuthForm` for name/email/password registration |
126
+
127
+ ### Composables
128
+
129
+ - `useUserLogin()` / `useUserRegistration()` โ€“ wrap the password routes above, and expose `isEnabled`/`passwordLoginEnabled`/`passkeyLoginEnabled`/`oauthProviders` computed from the module's public runtime config so the shipped pages (or your own) can render conditionally.
130
+ - `useUserPasswordReset()` โ€“ wraps the forgot/reset-password routes above (`requestReset`, `resetPassword`), exposing `isEnabled` based on `settings.passwordReset`.
131
+ - `useUserPasskeys()` โ€“ wraps `useWebAuthn` for registering/authenticating/listing passkeys.
132
+
133
+ All composables are registered via Nuxt's import ecosystem, so they can be overridden by re-declaring a composable of
134
+ the same name in the consuming app.
135
+
136
+
137
+ ## Contribution
138
+
139
+ <details>
140
+ <summary>Local development</summary>
141
+
142
+ ```bash
143
+ # Install dependencies
144
+ npm install
145
+
146
+ # Generate type stubs
147
+ npm run dev:prepare
148
+
149
+ # Develop with the playground
150
+ npm run dev
151
+
152
+ # Build the playground
153
+ npm run dev:build
154
+
155
+ # Run ESLint
156
+ npm run lint
157
+
158
+ # Run Vitest
159
+ npm run test
160
+ npm run test:watch
161
+
162
+ # Release new version
163
+ npm run release
164
+ ```
165
+
166
+ </details>
167
+
168
+
169
+ <!-- Badges -->
170
+ [npm-version-src]: https://img.shields.io/npm/v/@frigear-nu/users/latest.svg?style=flat&colorA=020420&colorB=00DC82
171
+ [npm-version-href]: https://npmjs.com/package/@frigear-nu/users
172
+
173
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@frigear-nu/users.svg?style=flat&colorA=020420&colorB=00DC82
174
+ [npm-downloads-href]: https://npm.chart.dev/@frigear-nu/users
175
+
176
+ [license-src]: https://img.shields.io/npm/l/@frigear-nu/users.svg?style=flat&colorA=020420&colorB=00DC82
177
+ [license-href]: https://npmjs.com/package/@frigear-nu/users
178
+
179
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt
180
+ [nuxt-href]: https://nuxt.com
@@ -0,0 +1,72 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ type AuthMethod = (string | 'passkeys' | 'emailPassword');
4
+ type AuthMethodObject = {
5
+ label: string;
6
+ value: AuthMethod;
7
+ icon?: string;
8
+ };
9
+ type AuthManifest = {
10
+ methods: AuthMethodObject[];
11
+ pages: {
12
+ login?: string;
13
+ register?: string;
14
+ };
15
+ };
16
+ declare const OAUTH_PROVIDERS: readonly ["github", "google"];
17
+ type OAuthProvider = typeof OAUTH_PROVIDERS[number];
18
+ type OAuthProviderDetails = {
19
+ label: string;
20
+ value: OAuthProvider;
21
+ icon?: string;
22
+ };
23
+ type PublicModuleOptions = {
24
+ password: boolean;
25
+ passwordReset: boolean;
26
+ webAuthn: boolean;
27
+ oauth: OAuthProvider[];
28
+ pages: {
29
+ login?: string;
30
+ register?: string;
31
+ };
32
+ };
33
+ type ModuleOptions = {
34
+ mode: 'server';
35
+ settings?: {
36
+ migrations?: boolean;
37
+ password?: boolean;
38
+ passwordReset?: boolean;
39
+ webAuthn?: boolean;
40
+ pages?: {
41
+ login?: string | boolean;
42
+ register?: string | boolean;
43
+ };
44
+ session?: {
45
+ mapper?: string;
46
+ };
47
+ oauth?: Partial<Record<OAuthProvider, boolean>>;
48
+ };
49
+ } | {
50
+ mode: 'client';
51
+ settings?: {
52
+ mapFromHttp?: string;
53
+ migrations?: false;
54
+ };
55
+ };
56
+
57
+ declare module 'nuxt/schema' {
58
+ interface NuxtConfig {
59
+ users?: ModuleOptions;
60
+ }
61
+ interface RuntimeConfig {
62
+ users?: ModuleOptions;
63
+ }
64
+ interface PublicRuntimeConfig {
65
+ authMethods: AuthMethodObject[];
66
+ users?: PublicModuleOptions;
67
+ }
68
+ }
69
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
70
+
71
+ export { OAUTH_PROVIDERS, _default as default };
72
+ export type { AuthManifest, AuthMethod, AuthMethodObject, ModuleOptions, OAuthProvider, OAuthProviderDetails, PublicModuleOptions };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@frigear-nu/users",
3
+ "configKey": "users",
4
+ "version": "1.0.3",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.3",
7
+ "unbuild": "unknown"
8
+ }
9
+ }
@@ -0,0 +1,207 @@
1
+ import { defineNuxtModule, createResolver, hasNuxtModule, addServerTemplate, addServerImportsDir, addServerHandler, addImports, addTemplate, extendPages } from '@nuxt/kit';
2
+ import { upperFirst } from 'scule';
3
+ import { registerLocales, registerDatabaseTable } from '@frigear-nu/module-kit/utils';
4
+
5
+ const OAUTH_PROVIDERS = ["github", "google"];
6
+
7
+ function resolvePagePath(setting, defaultPath) {
8
+ if (typeof setting === "string") return setting;
9
+ if (setting === true) return defaultPath;
10
+ return void 0;
11
+ }
12
+ const module$1 = defineNuxtModule({
13
+ meta: { name: "@frigear-nu/users", configKey: "users" },
14
+ defaults: {
15
+ mode: "server",
16
+ settings: {
17
+ migrations: true,
18
+ password: true,
19
+ webAuthn: false,
20
+ pages: {}
21
+ }
22
+ },
23
+ moduleDependencies: {
24
+ "@nuxthub/core": {
25
+ version: ">=0.0.1"
26
+ },
27
+ "@frigear-nu/module-kit": {
28
+ version: ">=0.0.1"
29
+ },
30
+ "@frigear-nu/notify": {
31
+ version: ">=0.0.1"
32
+ },
33
+ "@frigear-nu/menu": {
34
+ version: ">=0.0.1"
35
+ },
36
+ "nuxt-auth-utils": {
37
+ version: ">=0.0.1",
38
+ defaults: { webAuthn: true }
39
+ }
40
+ },
41
+ async setup(options, nuxt) {
42
+ if (options.mode === "client") {
43
+ console.log("Users module is running in client mode - will be built accordingly to support oauth.");
44
+ return;
45
+ }
46
+ const resolver = createResolver(import.meta.url);
47
+ registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
48
+ const settings = options.settings ?? {};
49
+ const withPassword = settings.password !== false;
50
+ const withPasswordReset = withPassword && settings.passwordReset !== false;
51
+ const withWebAuthn = settings.webAuthn === true;
52
+ const withMenus = hasNuxtModule("@frigear-nu/menu");
53
+ const withI18n = nuxt.options.modules?.some((mod) => mod === "@nuxtjs/i18n" || Array.isArray(mod) && mod[0] === "@nuxtjs/i18n");
54
+ const authMethods = [];
55
+ if (!withWebAuthn) {
56
+ nuxt.options.auth ||= {};
57
+ nuxt.options.auth.webAuthn = false;
58
+ }
59
+ const tablesToRegister = ["users"];
60
+ if (withWebAuthn) {
61
+ tablesToRegister.push("userPasskeys");
62
+ }
63
+ if (withPasswordReset) {
64
+ tablesToRegister.push("passwordResets");
65
+ }
66
+ await registerDatabaseTable(nuxt, {
67
+ name: tablesToRegister,
68
+ resolver,
69
+ schema: (dialect) => `./runtime/db/schema.${dialect}`
70
+ });
71
+ addServerTemplate({
72
+ filename: "#users/session-mapper",
73
+ getContents: async () => {
74
+ if (!settings.session?.mapper) return "export default (user) => user";
75
+ const mapperPath = await resolver.resolvePath(settings.session.mapper, { cwd: nuxt.options.rootDir });
76
+ return `export { default } from ${JSON.stringify(mapperPath)}`;
77
+ }
78
+ });
79
+ addServerImportsDir(resolver.resolve("./runtime/server/utils"));
80
+ addServerHandler({
81
+ route: "/auth/logout",
82
+ method: "get",
83
+ handler: resolver.resolve("./runtime/server/routes/auth/logout.get")
84
+ });
85
+ if (withPassword) {
86
+ authMethods.push({
87
+ label: withI18n ? "auth.emailPassword.label" : "Email & Password",
88
+ value: "emailPassword",
89
+ icon: "i-lucide-user-lock"
90
+ });
91
+ addServerHandler({
92
+ route: "/api/auth/login",
93
+ handler: resolver.resolve("./runtime/server/routes/auth/login.post")
94
+ });
95
+ addServerHandler({
96
+ route: "/api/auth/register",
97
+ handler: resolver.resolve("./runtime/server/routes/auth/register.post")
98
+ });
99
+ }
100
+ if (withPasswordReset) {
101
+ addServerHandler({
102
+ route: "/api/auth/forgot-password",
103
+ handler: resolver.resolve("./runtime/server/routes/auth/forgot-password.post")
104
+ });
105
+ addServerHandler({
106
+ route: "/api/auth/reset-password",
107
+ handler: resolver.resolve("./runtime/server/routes/auth/reset-password.post")
108
+ });
109
+ }
110
+ addImports([
111
+ { name: "useUserLogin", from: resolver.resolve("./runtime/app/composables/useUserLogin") },
112
+ {
113
+ name: "useUserRegistration",
114
+ from: resolver.resolve("./runtime/app/composables/useUserRegistration")
115
+ },
116
+ { name: "useUserPasswordReset", from: resolver.resolve("./runtime/app/composables/useUserPasswordReset") }
117
+ ]);
118
+ if (withWebAuthn) {
119
+ authMethods.push({
120
+ label: withI18n ? "auth.passkeys.label" : "Passkey",
121
+ value: "passkeys",
122
+ icon: "i-lucide-key"
123
+ });
124
+ addServerHandler({
125
+ route: "/api/auth/webauthn/register",
126
+ handler: resolver.resolve("./runtime/server/routes/auth/webauthn/register.post")
127
+ });
128
+ addServerHandler({
129
+ route: "/api/auth/webauthn/authenticate",
130
+ handler: resolver.resolve("./runtime/server/routes/auth/webauthn/authenticate.post")
131
+ });
132
+ addServerHandler({
133
+ route: "/api/auth/webauthn/credentials",
134
+ handler: resolver.resolve("./runtime/server/routes/auth/webauthn/credentials/index.get")
135
+ });
136
+ addServerHandler({
137
+ route: "/api/auth/webauthn/credentials/:id",
138
+ method: "delete",
139
+ handler: resolver.resolve("./runtime/server/routes/auth/webauthn/credentials/[id].delete")
140
+ });
141
+ }
142
+ addImports([{
143
+ name: "useUserPasskeys",
144
+ from: resolver.resolve("./runtime/app/composables/useUserPasskeys")
145
+ }]);
146
+ const enabledOauthProviders = [];
147
+ for (const provider of OAUTH_PROVIDERS) {
148
+ if (!settings.oauth?.[provider]) continue;
149
+ authMethods.push({
150
+ label: withI18n ? `auth.oauth.${provider}.label` : upperFirst(provider),
151
+ value: provider
152
+ });
153
+ addServerHandler({
154
+ route: `/api/auth/${provider}`,
155
+ handler: resolver.resolve(`./runtime/server/routes/auth/${provider}.get`)
156
+ });
157
+ enabledOauthProviders.push(provider);
158
+ }
159
+ const loginPath = withPassword || enabledOauthProviders.length > 0 ? resolvePagePath(settings.pages?.login, "/login") : void 0;
160
+ const registerPath = withPassword ? resolvePagePath(settings.pages?.register, "/register") : void 0;
161
+ nuxt.options.runtimeConfig.public.authMethods = authMethods;
162
+ const authManifest = {
163
+ methods: authMethods,
164
+ pages: {
165
+ login: loginPath,
166
+ register: registerPath
167
+ }
168
+ };
169
+ addTemplate({
170
+ filename: "users/auth.manifest.json",
171
+ write: true,
172
+ getContents: () => JSON.stringify(authManifest, null, 2)
173
+ });
174
+ if (loginPath || registerPath) {
175
+ extendPages((pages) => {
176
+ const existingPaths = new Set(pages.map((page) => page.path));
177
+ if (loginPath && !existingPaths.has(loginPath)) {
178
+ pages.push({
179
+ name: "users-login",
180
+ path: loginPath,
181
+ file: resolver.resolve("./runtime/app/pages/login.vue")
182
+ });
183
+ }
184
+ if (registerPath && !existingPaths.has(registerPath)) {
185
+ pages.push({
186
+ name: "users-register",
187
+ path: registerPath,
188
+ file: resolver.resolve("./runtime/app/pages/register.vue")
189
+ });
190
+ }
191
+ });
192
+ }
193
+ if (withMenus) {
194
+ const { registerMenuSource } = await import('@frigear-nu/menu/utils');
195
+ registerMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "account.dropdown" });
196
+ }
197
+ nuxt.options.runtimeConfig.public.users = {
198
+ password: withPassword,
199
+ passwordReset: withPasswordReset,
200
+ webAuthn: withWebAuthn,
201
+ oauth: enabledOauthProviders,
202
+ pages: { login: loginPath, register: registerPath }
203
+ };
204
+ }
205
+ });
206
+
207
+ export { OAUTH_PROVIDERS, module$1 as default };
@@ -0,0 +1,5 @@
1
+ export declare const useAuthManifest: () => {
2
+ readonly name: "users";
3
+ readonly version: "1.0.0";
4
+ readonly description: "User management module for authentication and authorization.";
5
+ };
@@ -0,0 +1,7 @@
1
+ export const useAuthManifest = () => {
2
+ return {
3
+ name: "users",
4
+ version: "1.0.0",
5
+ description: "User management module for authentication and authorization."
6
+ };
7
+ };
@@ -0,0 +1,12 @@
1
+ export declare const useUserLogin: () => {
2
+ login: (payload: {
3
+ email: string;
4
+ password: string;
5
+ }) => Promise<void>;
6
+ pending: any;
7
+ error: any;
8
+ isEnabled: any;
9
+ passwordLoginEnabled: any;
10
+ passkeyLoginEnabled: any;
11
+ oauthProviders: any;
12
+ };
@@ -0,0 +1,26 @@
1
+ import { OAUTH_PROVIDER_META } from "../utils/oauth-providers.js";
2
+ export const useUserLogin = () => {
3
+ const config = useRuntimeConfig().public.users;
4
+ const passwordLoginEnabled = computed(() => config?.password === true);
5
+ const passkeyLoginEnabled = computed(() => config?.webAuthn === true);
6
+ const oauthProviders = computed(() => (config?.oauth ?? []).map((provider) => {
7
+ return typeof provider === "object" ? provider : OAUTH_PROVIDER_META[provider];
8
+ }));
9
+ const isEnabled = computed(() => passwordLoginEnabled.value || passkeyLoginEnabled.value || oauthProviders.value.length > 0);
10
+ const pending = ref(false);
11
+ const error = ref(null);
12
+ async function login(payload) {
13
+ pending.value = true;
14
+ error.value = null;
15
+ try {
16
+ await $fetch("/api/auth/login", { method: "POST", body: payload });
17
+ await useUserSession().fetch();
18
+ } catch (err) {
19
+ error.value = err instanceof Error ? err.message : "Failed to log in.";
20
+ throw err;
21
+ } finally {
22
+ pending.value = false;
23
+ }
24
+ }
25
+ return { login, pending, error, isEnabled, passwordLoginEnabled, passkeyLoginEnabled, oauthProviders };
26
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useUserPasskeys: () => {
2
+ isEnabled: any;
3
+ registerPasskey: (userName: string) => Promise<void>;
4
+ authenticateWithPasskey: (userName?: string) => Promise<void>;
5
+ listPasskeys: () => any;
6
+ removePasskey: (id: string) => any;
7
+ };
@@ -0,0 +1,22 @@
1
+ export const useUserPasskeys = () => {
2
+ const config = useRuntimeConfig().public.users;
3
+ const isEnabled = computed(() => config?.webAuthn === true);
4
+ const { register, authenticate } = useWebAuthn({
5
+ registerEndpoint: "/api/auth/webauthn/register",
6
+ authenticateEndpoint: "/api/auth/webauthn/authenticate"
7
+ });
8
+ const { fetch: fetchUserSession } = useUserSession();
9
+ async function registerPasskey(userName) {
10
+ await register({ userName }).then(fetchUserSession);
11
+ }
12
+ async function authenticateWithPasskey(userName) {
13
+ await authenticate(userName).then(fetchUserSession);
14
+ }
15
+ function listPasskeys() {
16
+ return $fetch("/api/auth/webauthn/credentials");
17
+ }
18
+ function removePasskey(id) {
19
+ return $fetch(`/api/auth/webauthn/credentials/${id}`, { method: "DELETE" });
20
+ }
21
+ return { isEnabled, registerPasskey, authenticateWithPasskey, listPasskeys, removePasskey };
22
+ };
@@ -0,0 +1,13 @@
1
+ export declare const useUserPasswordReset: () => {
2
+ requestReset: (payload: {
3
+ email: string;
4
+ }) => Promise<void>;
5
+ resetPassword: (payload: {
6
+ code: string;
7
+ password: string;
8
+ confirmPassword: string;
9
+ }) => Promise<void>;
10
+ pending: any;
11
+ error: any;
12
+ isEnabled: any;
13
+ };
@@ -0,0 +1,32 @@
1
+ export const useUserPasswordReset = () => {
2
+ const config = useRuntimeConfig().public.users;
3
+ const isEnabled = computed(() => config?.passwordReset === true);
4
+ const pending = ref(false);
5
+ const error = ref(null);
6
+ async function requestReset(payload) {
7
+ pending.value = true;
8
+ error.value = null;
9
+ try {
10
+ await $fetch("/api/auth/forgot-password", { method: "POST", body: payload });
11
+ } catch (err) {
12
+ error.value = err instanceof Error ? err.message : "Failed to request a password reset.";
13
+ throw err;
14
+ } finally {
15
+ pending.value = false;
16
+ }
17
+ }
18
+ async function resetPassword(payload) {
19
+ pending.value = true;
20
+ error.value = null;
21
+ try {
22
+ await $fetch("/api/auth/reset-password", { method: "POST", body: payload });
23
+ await useUserSession().fetch();
24
+ } catch (err) {
25
+ error.value = err instanceof Error ? err.message : "Failed to reset password.";
26
+ throw err;
27
+ } finally {
28
+ pending.value = false;
29
+ }
30
+ }
31
+ return { requestReset, resetPassword, pending, error, isEnabled };
32
+ };
@@ -0,0 +1,10 @@
1
+ export declare const useUserRegistration: () => {
2
+ register: (payload: {
3
+ name: string;
4
+ email: string;
5
+ password: string;
6
+ }) => Promise<void>;
7
+ pending: any;
8
+ error: any;
9
+ isEnabled: any;
10
+ };
@@ -0,0 +1,20 @@
1
+ export const useUserRegistration = () => {
2
+ const config = useRuntimeConfig().public.users;
3
+ const isEnabled = computed(() => config?.password === true);
4
+ const pending = ref(false);
5
+ const error = ref(null);
6
+ async function register(payload) {
7
+ pending.value = true;
8
+ error.value = null;
9
+ try {
10
+ await $fetch("/api/auth/register", { method: "POST", body: payload });
11
+ await useUserSession().fetch();
12
+ } catch (err) {
13
+ error.value = err instanceof Error ? err.message : "Failed to register.";
14
+ throw err;
15
+ } finally {
16
+ pending.value = false;
17
+ }
18
+ }
19
+ return { register, pending, error, isEnabled };
20
+ };
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;