@frigear-nu/users 1.0.7 → 1.0.9
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 +19 -136
- package/dist/module.d.mts +35 -48
- package/dist/module.json +1 -1
- package/dist/module.mjs +97 -169
- package/dist/runtime/admin-menus.js +16 -0
- package/dist/runtime/app/pages/admin-user.vue +52 -0
- package/dist/runtime/app/pages/admin.vue +252 -0
- package/dist/runtime/app/tabs/Overview.d.vue.ts +11 -0
- package/dist/runtime/app/tabs/Overview.vue +206 -0
- package/dist/runtime/app/tabs/Overview.vue.d.ts +11 -0
- package/dist/runtime/app/utils/admin-user.d.ts +22 -0
- package/dist/runtime/app/utils/admin-user.js +0 -0
- package/dist/runtime/app/widgets/NewMembers.d.vue.ts +3 -0
- package/dist/runtime/app/widgets/NewMembers.vue +66 -0
- package/dist/runtime/app/widgets/NewMembers.vue.d.ts +3 -0
- package/dist/runtime/db/email-changes.sqlite.d.ts +202 -0
- package/dist/runtime/db/email-changes.sqlite.js +16 -0
- package/dist/runtime/db/schema.sqlite.d.ts +5 -212
- package/dist/runtime/db/schema.sqlite.js +2 -21
- package/dist/runtime/i18n/lang/da.json +62 -80
- package/dist/runtime/i18n/lang/en.json +62 -80
- package/dist/runtime/server/mcp/tools/get-my-profile.js +6 -0
- package/dist/runtime/server/routes/admin/new-members.get.js +16 -0
- package/dist/runtime/server/routes/admin/roles.get.js +4 -0
- package/dist/runtime/server/routes/admin/user-resend.post.js +19 -0
- package/dist/runtime/server/routes/admin/user.delete.js +21 -0
- package/dist/runtime/server/routes/admin/user.get.js +32 -0
- package/dist/runtime/server/routes/admin/user.patch.js +45 -0
- package/dist/runtime/server/routes/admin/users.get.js +59 -0
- package/dist/runtime/server/routes/admin/users.post.js +33 -0
- package/dist/runtime/server/routes/me/change-email.post.js +35 -0
- package/dist/runtime/server/routes/me/change-password.post.js +27 -0
- package/dist/runtime/server/routes/me/profile.post.d.ts +2 -0
- package/dist/runtime/server/routes/me/profile.post.js +17 -0
- package/dist/runtime/server/routes/me/revert-email-change.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/revert-email-change.get.js +24 -0
- package/dist/runtime/server/routes/me/verify-email-change.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/verify-email-change.get.js +37 -0
- package/dist/runtime/server/user-store.d.ts +3 -0
- package/dist/runtime/server/user-store.js +70 -0
- package/dist/runtime/server/utils/admin.d.ts +59 -0
- package/dist/runtime/server/utils/admin.js +53 -0
- package/dist/runtime/server/utils/notifications.d.ts +16 -0
- package/dist/runtime/server/utils/notifications.js +32 -0
- package/dist/runtime/server/utils/require-user.d.ts +12 -0
- package/dist/runtime/server/utils/require-user.js +9 -0
- package/dist/runtime/utils/index.d.ts +19 -0
- package/dist/runtime/utils/index.js +11 -0
- package/dist/types.d.mts +2 -2
- package/package.json +31 -17
- package/dist/runtime/app/composables/useAuthManifest.d.ts +0 -5
- package/dist/runtime/app/composables/useAuthManifest.js +0 -7
- package/dist/runtime/app/composables/useUserLogin.d.ts +0 -12
- package/dist/runtime/app/composables/useUserLogin.js +0 -26
- package/dist/runtime/app/composables/useUserPasskeys.d.ts +0 -7
- package/dist/runtime/app/composables/useUserPasskeys.js +0 -22
- package/dist/runtime/app/composables/useUserPasswordReset.d.ts +0 -13
- package/dist/runtime/app/composables/useUserPasswordReset.js +0 -32
- package/dist/runtime/app/composables/useUserRegistration.d.ts +0 -10
- package/dist/runtime/app/composables/useUserRegistration.js +0 -20
- package/dist/runtime/app/pages/login.vue +0 -68
- package/dist/runtime/app/pages/register.vue +0 -40
- package/dist/runtime/app/utils/oauth-providers.d.ts +0 -13
- package/dist/runtime/app/utils/oauth-providers.js +0 -4
- package/dist/runtime/menus.js +0 -12
- package/dist/runtime/server/routes/auth/forgot-password.post.js +0 -19
- package/dist/runtime/server/routes/auth/github.get.js +0 -7
- package/dist/runtime/server/routes/auth/google.get.js +0 -6
- package/dist/runtime/server/routes/auth/login.post.js +0 -15
- package/dist/runtime/server/routes/auth/logout.get.js +0 -4
- package/dist/runtime/server/routes/auth/register.post.js +0 -18
- package/dist/runtime/server/routes/auth/reset-password.post.js +0 -29
- package/dist/runtime/server/routes/auth/webauthn/authenticate.post.js +0 -34
- package/dist/runtime/server/routes/auth/webauthn/credentials/[id].delete.js +0 -9
- package/dist/runtime/server/routes/auth/webauthn/credentials/index.get.js +0 -8
- package/dist/runtime/server/routes/auth/webauthn/register.post.js +0 -42
- package/dist/runtime/server/utils/oauth.d.ts +0 -8
- package/dist/runtime/server/utils/oauth.js +0 -18
- package/dist/runtime/server/utils/password-reset.d.ts +0 -22
- package/dist/runtime/server/utils/password-reset.js +0 -14
- package/dist/runtime/server/utils/session.d.ts +0 -11
- package/dist/runtime/server/utils/session.js +0 -5
- /package/dist/runtime/{menus.d.ts → admin-menus.d.ts} +0 -0
- /package/dist/runtime/app/pages/{login.d.vue.ts → admin-user.d.vue.ts} +0 -0
- /package/dist/runtime/app/pages/{login.vue.d.ts → admin-user.vue.d.ts} +0 -0
- /package/dist/runtime/app/pages/{register.d.vue.ts → admin.d.vue.ts} +0 -0
- /package/dist/runtime/app/pages/{register.vue.d.ts → admin.vue.d.ts} +0 -0
- /package/dist/runtime/server/{routes/auth/forgot-password.post.d.ts → mcp/tools/get-my-profile.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/github.get.d.ts → admin/new-members.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/google.get.d.ts → admin/roles.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/login.post.d.ts → admin/user-resend.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/logout.get.d.ts → admin/user.delete.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/register.post.d.ts → admin/user.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/reset-password.post.d.ts → admin/user.patch.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/authenticate.post.d.ts → admin/users.get.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/credentials/[id].delete.d.ts → admin/users.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/credentials/index.get.d.ts → me/change-email.post.d.ts} +0 -0
- /package/dist/runtime/server/routes/{auth/webauthn/register.post.d.ts → me/change-password.post.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -5,167 +5,50 @@
|
|
|
5
5
|
[![License][license-src]][license-href]
|
|
6
6
|
[![Nuxt][nuxt-src]][nuxt-href]
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The user entity of the main frigear app: the `users` table, staff administration of users, and what a signed-in user can
|
|
9
|
+
change about themselves. How people sign in lives in [`@frigear-nu/auth`](../auth), which this module installs.
|
|
9
10
|
|
|
10
11
|
## Features
|
|
11
12
|
|
|
12
|
-
- ⛰
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
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.
|
|
13
|
+
- ⛰ The `users` table and its schema, extended by other modules (credentials by `auth`, `role` by `authorization`, ...).
|
|
14
|
+
- 🛠 Staff administration (`settings.admin`): list, create, edit, delete and re-invite users, a "new members" widget and
|
|
15
|
+
an admin page (with `@frigear-nu/admin`). Policy is the host's, through the `users:admin:authorize` hook.
|
|
16
|
+
- 🧑 Self-service: change profile, email (optionally confirmed from the inbox) and password.
|
|
17
|
+
- 🧩 `requireUser` / `getUser` for server routes, and `extendUsersAdmin` for modules that add to the admin user page.
|
|
18
|
+
- 🔌 Registers the user store `@frigear-nu/auth` reads and writes users through.
|
|
21
19
|
|
|
22
20
|
## Quick Setup
|
|
23
21
|
|
|
24
|
-
Install the module to your Nuxt application with one command:
|
|
25
|
-
|
|
26
22
|
```bash
|
|
27
23
|
npx nuxt module add @frigear-nu/users
|
|
28
24
|
```
|
|
29
25
|
|
|
30
|
-
|
|
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`:
|
|
26
|
+
This module requires [`@nuxthub/core`](https://hub.nuxt.com) in the host app. Generate and commit a migration for the
|
|
27
|
+
tables it contributes (see the module-kit migrations guide).
|
|
38
28
|
|
|
39
29
|
```ts
|
|
40
30
|
export default defineNuxtConfig({
|
|
41
31
|
modules: ['@nuxthub/core', '@frigear-nu/users'],
|
|
42
32
|
users: {
|
|
43
|
-
mode: 'server',
|
|
44
33
|
settings: {
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
//
|
|
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',
|
|
34
|
+
admin: true, // staff administration; `{ page: false }` = API only
|
|
35
|
+
verifyEmailChange: true, // a new address must be confirmed from its inbox
|
|
36
|
+
profilePath: '/account/profile', // where that confirmation lands
|
|
37
|
+
mcp: false, // the `get-my-profile` MCP tool
|
|
90
38
|
},
|
|
91
39
|
},
|
|
92
40
|
})
|
|
93
41
|
```
|
|
94
42
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
import type { EmailDriver } from '@frigear-nu/notify/types'
|
|
43
|
+
See the [documentation](../../apps/docs/content/4.modules/18.users.md) for the routes, hooks and the user page extension
|
|
44
|
+
points, and [`@frigear-nu/auth`](../auth/README.md) for sign-in (`authentication.settings`).
|
|
98
45
|
|
|
99
|
-
|
|
100
|
-
// ... call your provider's API with notification.to/subject/body/text
|
|
101
|
-
}
|
|
46
|
+
## Development
|
|
102
47
|
|
|
103
|
-
|
|
48
|
+
```bash
|
|
49
|
+
pnpm --filter '@frigear-nu/users' test
|
|
104
50
|
```
|
|
105
51
|
|
|
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
52
|
<!-- Badges -->
|
|
170
53
|
[npm-version-src]: https://img.shields.io/npm/v/@frigear-nu/users/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
171
54
|
[npm-version-href]: https://npmjs.com/package/@frigear-nu/users
|
package/dist/module.d.mts
CHANGED
|
@@ -1,72 +1,59 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { UsersAdminContext, UsersAdminRolesContext } from '../dist/runtime/server/utils/admin.js';
|
|
2
3
|
|
|
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
4
|
type PublicModuleOptions = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
/** Where the page of the signed-in user's profile lives; the email change confirmation link lands there. */
|
|
6
|
+
profilePath?: string;
|
|
7
|
+
/** Whether `settings.mcp` is on. */
|
|
8
|
+
mcp: boolean;
|
|
28
9
|
pages: {
|
|
29
|
-
|
|
30
|
-
register?: string;
|
|
10
|
+
admin?: string;
|
|
31
11
|
};
|
|
32
12
|
};
|
|
33
13
|
type ModuleOptions = {
|
|
34
|
-
mode: 'server';
|
|
35
14
|
settings?: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
session?: {
|
|
45
|
-
mapper?: string;
|
|
15
|
+
/**
|
|
16
|
+
* User administration for staff: list/create/edit users (`/api/admin/users`), a "new members" widget and an
|
|
17
|
+
* admin page. Who may do what is decided by the host in the `users:admin:authorize` Nitro hook (denied by
|
|
18
|
+
* default). `page` is the admin page path (`true` = `/admin/users`, `false` = no page).
|
|
19
|
+
*/
|
|
20
|
+
admin?: boolean | {
|
|
21
|
+
page?: string | boolean;
|
|
46
22
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A new email address only takes effect once its owner confirms it through an emailed link; the old address then
|
|
25
|
+
* gets a notice with a link to revert the change. Defaults to `false` (applied immediately).
|
|
26
|
+
*/
|
|
27
|
+
verifyEmailChange?: boolean;
|
|
28
|
+
/** Where the confirmation link of an email change lands (`?email-changed=1` or `?error=email-change`). Defaults to `/`. */
|
|
29
|
+
profilePath?: string;
|
|
30
|
+
/** Expose the MCP tools of this module (`get-my-profile`) on the MCP endpoint. Needs `@frigear-nu/mcp`. Defaults to `false`. */
|
|
31
|
+
mcp?: boolean;
|
|
54
32
|
};
|
|
55
33
|
};
|
|
56
34
|
|
|
35
|
+
declare module 'nitropack' {
|
|
36
|
+
interface NitroRuntimeHooks {
|
|
37
|
+
/** Staff gate of the users admin (`settings.admin`): set `ctx.allowed = true` to allow `ctx.action`. Denied by default. */
|
|
38
|
+
'users:admin:authorize': (ctx: UsersAdminContext) => void | Promise<void>;
|
|
39
|
+
/** Roles the signed-in user may assign in the users admin: set `ctx.roles`. Defaults to the roles in use. */
|
|
40
|
+
'users:admin:roles': (ctx: UsersAdminRolesContext) => void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
57
43
|
declare module 'nuxt/schema' {
|
|
58
44
|
interface NuxtConfig {
|
|
59
45
|
users?: ModuleOptions;
|
|
60
46
|
}
|
|
61
47
|
interface RuntimeConfig {
|
|
62
|
-
users?:
|
|
48
|
+
users?: {
|
|
49
|
+
verifyEmailChange: boolean;
|
|
50
|
+
};
|
|
63
51
|
}
|
|
64
52
|
interface PublicRuntimeConfig {
|
|
65
|
-
authMethods: AuthMethodObject[];
|
|
66
53
|
users?: PublicModuleOptions;
|
|
67
54
|
}
|
|
68
55
|
}
|
|
69
56
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
70
57
|
|
|
71
|
-
export {
|
|
72
|
-
export type {
|
|
58
|
+
export { _default as default };
|
|
59
|
+
export type { ModuleOptions, PublicModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,207 +1,135 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerImportsDir, addServerHandler, hasNuxtModule } from '@nuxt/kit';
|
|
2
|
+
import { registerTailwindSource, registerLocales, registerDatabaseTable, moduleApiUrl, resolvePagePath, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
|
|
3
|
+
import { setAuthUserStore, addAuthScope } from '@frigear-nu/auth/utils';
|
|
4
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
5
|
const module$1 = defineNuxtModule({
|
|
13
6
|
meta: { name: "@frigear-nu/users", configKey: "users" },
|
|
14
7
|
defaults: {
|
|
15
|
-
|
|
16
|
-
settings: {
|
|
17
|
-
migrations: true,
|
|
18
|
-
password: true,
|
|
19
|
-
webAuthn: false,
|
|
20
|
-
pages: {}
|
|
21
|
-
}
|
|
8
|
+
settings: {}
|
|
22
9
|
},
|
|
23
|
-
|
|
10
|
+
// `@frigear-nu/mcp` is only installed when `settings.mcp` is on.
|
|
11
|
+
moduleDependencies: (nuxt) => ({
|
|
24
12
|
"@nuxthub/core": {
|
|
25
13
|
version: ">=0.0.1"
|
|
26
14
|
},
|
|
27
15
|
"@frigear-nu/module-kit": {
|
|
28
16
|
version: ">=0.0.1"
|
|
29
17
|
},
|
|
30
|
-
|
|
18
|
+
// Sign-in, sessions and `requireAuth`: the users module only says who the users are.
|
|
19
|
+
"@frigear-nu/auth": {
|
|
31
20
|
version: ">=0.0.1"
|
|
32
21
|
},
|
|
33
|
-
|
|
22
|
+
// Email and password change notices are dispatched through it.
|
|
23
|
+
"@frigear-nu/notify": {
|
|
34
24
|
version: ">=0.0.1"
|
|
35
25
|
},
|
|
36
|
-
"
|
|
26
|
+
"@frigear-nu/menu": {
|
|
37
27
|
version: ">=0.0.1",
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
28
|
+
optional: true
|
|
29
|
+
},
|
|
30
|
+
"@frigear-nu/widget": {
|
|
31
|
+
version: ">=0.0.0",
|
|
32
|
+
optional: true
|
|
33
|
+
},
|
|
34
|
+
// Provides the shared page components of the admin pages (`AdminPage`, `AdminTable`, ...).
|
|
35
|
+
"@frigear-nu/admin": {
|
|
36
|
+
version: ">=0.0.0",
|
|
37
|
+
optional: true
|
|
38
|
+
},
|
|
39
|
+
...nuxt.options.users?.settings?.mcp === true ? { "@frigear-nu/mcp": { version: ">=0.0.1" } } : {}
|
|
40
|
+
}),
|
|
41
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
42
|
const resolver = createResolver(import.meta.url);
|
|
43
|
+
registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
|
|
47
44
|
registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
|
|
48
45
|
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
46
|
await registerDatabaseTable(nuxt, {
|
|
67
|
-
name:
|
|
47
|
+
name: ["users"],
|
|
68
48
|
resolver,
|
|
69
49
|
schema: (dialect) => `./runtime/db/schema.${dialect}`
|
|
70
50
|
});
|
|
71
|
-
|
|
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
|
-
});
|
|
51
|
+
setAuthUserStore(nuxt, resolver.resolve("./runtime/server/user-store"));
|
|
79
52
|
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
});
|
|
53
|
+
for (const [path, file] of [
|
|
54
|
+
["me/profile", "profile.post"],
|
|
55
|
+
["me/change-email", "change-email.post"],
|
|
56
|
+
["me/change-password", "change-password.post"]
|
|
57
|
+
]) {
|
|
58
|
+
addServerHandler({ route: moduleApiUrl("users", path), method: "post", handler: resolver.resolve(`./runtime/server/routes/me/${file}`) });
|
|
99
59
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
60
|
+
if (settings.verifyEmailChange) {
|
|
61
|
+
for (const file of ["verify-email-change", "revert-email-change"]) {
|
|
62
|
+
addServerHandler({
|
|
63
|
+
route: `/auth/${file}`,
|
|
64
|
+
method: "get",
|
|
65
|
+
handler: resolver.resolve(`./runtime/server/routes/me/${file}.get`)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
await registerDatabaseTable(nuxt, {
|
|
69
|
+
name: ["accountEmailChanges"],
|
|
70
|
+
resolver,
|
|
71
|
+
schema: (dialect) => `./runtime/db/email-changes.${dialect}`
|
|
108
72
|
});
|
|
109
73
|
}
|
|
110
|
-
|
|
111
|
-
{
|
|
112
|
-
{
|
|
113
|
-
|
|
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
|
-
});
|
|
74
|
+
if (settings.mcp === true) {
|
|
75
|
+
const { addMcpDefinitions } = await import('@frigear-nu/mcp/utils');
|
|
76
|
+
addAuthScope(nuxt, { name: "profile:read", description: "Read your own name, email and role (MCP)" });
|
|
77
|
+
addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
|
|
141
78
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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);
|
|
79
|
+
nuxt.options.runtimeConfig.users = { verifyEmailChange: settings.verifyEmailChange === true };
|
|
80
|
+
const withAdmin = !!settings.admin;
|
|
81
|
+
const adminOptions = typeof settings.admin === "object" ? settings.admin : {};
|
|
82
|
+
const withAdminShell = hasNuxtModule("@frigear-nu/admin");
|
|
83
|
+
if (withAdmin && !withAdminShell) {
|
|
84
|
+
console.warn("[@frigear-nu/users] `settings.admin` is on, but `@frigear-nu/admin` is not installed: the admin API is registered, the admin pages are not.");
|
|
158
85
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
86
|
+
const adminPagePath = withAdmin && withAdminShell ? resolvePagePath(adminOptions.page ?? true, (await import('@frigear-nu/admin/utils')).adminRoute(nuxt, "users")) : void 0;
|
|
87
|
+
if (withAdmin) {
|
|
88
|
+
for (const [method, path, file] of [
|
|
89
|
+
["get", "/api/admin/users", "users.get"],
|
|
90
|
+
["post", "/api/admin/users", "users.post"],
|
|
91
|
+
["get", "/api/admin/users/new-members", "new-members.get"],
|
|
92
|
+
["get", "/api/admin/users/roles", "roles.get"],
|
|
93
|
+
["get", "/api/admin/users/:id", "user.get"],
|
|
94
|
+
["patch", "/api/admin/users/:id", "user.patch"],
|
|
95
|
+
["delete", "/api/admin/users/:id", "user.delete"],
|
|
96
|
+
["post", "/api/admin/users/:id/resend", "user-resend.post"]
|
|
97
|
+
]) {
|
|
98
|
+
addServerHandler({ route: path, method, handler: resolver.resolve(`./runtime/server/routes/admin/${file}`) });
|
|
99
|
+
}
|
|
100
|
+
if (adminPagePath) {
|
|
101
|
+
addModulePages("@frigear-nu/users", resolver, [
|
|
102
|
+
{ name: "users-admin", path: adminPagePath, file: "./runtime/app/pages/admin.vue" },
|
|
103
|
+
{ name: "users-admin-user", path: `${adminPagePath.replace(/\/+$/, "")}/:id(\\d+)`, file: "./runtime/app/pages/admin-user.vue" }
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
if (hasNuxtModule("@frigear-nu/widget")) {
|
|
107
|
+
const { extendWidgets, extendTabs } = await import('@frigear-nu/widget/utils');
|
|
108
|
+
extendTabs(nuxt, "admin.users", {
|
|
109
|
+
id: "overview",
|
|
110
|
+
component: resolver.resolve("./runtime/app/tabs/Overview.vue"),
|
|
111
|
+
order: 0,
|
|
112
|
+
label: "Overview",
|
|
113
|
+
labelKey: "users.admin.tabs.overview",
|
|
114
|
+
icon: "i-lucide-user"
|
|
115
|
+
});
|
|
116
|
+
extendWidgets(nuxt, "admin.dashboard", {
|
|
117
|
+
id: "users-new-members",
|
|
118
|
+
component: resolver.resolve("./runtime/app/widgets/NewMembers.vue"),
|
|
119
|
+
order: 20,
|
|
120
|
+
span: 2
|
|
121
|
+
});
|
|
167
122
|
}
|
|
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
123
|
}
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
registerMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "account.dropdown" });
|
|
124
|
+
if (adminPagePath) {
|
|
125
|
+
addOptionalMenuSource(nuxt, { file: resolver.resolve("./runtime/admin-menus"), menu: "admin" });
|
|
196
126
|
}
|
|
197
127
|
nuxt.options.runtimeConfig.public.users = {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
oauth: enabledOauthProviders,
|
|
202
|
-
pages: { login: loginPath, register: registerPath }
|
|
128
|
+
profilePath: settings.profilePath,
|
|
129
|
+
mcp: settings.mcp === true,
|
|
130
|
+
pages: { admin: adminPagePath }
|
|
203
131
|
};
|
|
204
132
|
}
|
|
205
133
|
});
|
|
206
134
|
|
|
207
|
-
export {
|
|
135
|
+
export { module$1 as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineMenuSource, extendMenuItem } from "@frigear-nu/menu/utils";
|
|
2
|
+
export default defineMenuSource(() => {
|
|
3
|
+
const adminPage = useRuntimeConfig().public.users?.pages?.admin;
|
|
4
|
+
if (adminPage) {
|
|
5
|
+
extendMenuItem("admin.nav", {
|
|
6
|
+
id: "users-admin",
|
|
7
|
+
label: "Users",
|
|
8
|
+
labelKey: "users.admin.nav.label",
|
|
9
|
+
description: "Manage the users of the system.",
|
|
10
|
+
descriptionKey: "users.admin.nav.description",
|
|
11
|
+
icon: "i-lucide-users",
|
|
12
|
+
to: adminPage,
|
|
13
|
+
order: 10
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|