@frigear-nu/users 1.1.3 → 1.1.4

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 (49) hide show
  1. package/dist/module.d.mts +21 -1
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +25 -30
  4. package/dist/runtime/app/components/UserCreateSlideover.vue +2 -1
  5. package/dist/runtime/app/composables/useUserActions.d.ts +1 -1
  6. package/dist/runtime/app/composables/useUserActions.js +6 -3
  7. package/dist/runtime/app/pages/admin-user.vue +14 -5
  8. package/dist/runtime/app/pages/admin.vue +85 -75
  9. package/dist/runtime/app/pages/revert-email-change.vue +3 -2
  10. package/dist/runtime/app/pages/verify-email-change.vue +3 -2
  11. package/dist/runtime/app/tabs/Overview.vue +51 -53
  12. package/dist/runtime/app/utils/admin-user.d.ts +4 -17
  13. package/dist/runtime/app/widgets/NewUsers.vue +2 -1
  14. package/dist/runtime/app/widgets/NewUsersStat.vue +2 -1
  15. package/dist/runtime/i18n/lang/da.json +5 -3
  16. package/dist/runtime/i18n/lang/en.json +5 -3
  17. package/dist/runtime/server/routes/admin/new.get.js +2 -8
  18. package/dist/runtime/server/routes/admin/user-resend.post.js +3 -13
  19. package/dist/runtime/server/routes/admin/user.delete.js +6 -15
  20. package/dist/runtime/server/routes/admin/user.get.js +6 -16
  21. package/dist/runtime/server/routes/admin/user.patch.js +13 -23
  22. package/dist/runtime/server/routes/admin/users.get.js +24 -28
  23. package/dist/runtime/server/routes/admin/users.post.js +12 -13
  24. package/dist/runtime/server/routes/me/email-change-confirm.post.js +7 -11
  25. package/dist/runtime/server/routes/me/email-change-revert.get.js +2 -1
  26. package/dist/runtime/server/routes/me/email-change-revert.post.js +5 -7
  27. package/dist/runtime/server/routes/me/email-change.get.js +2 -1
  28. package/dist/runtime/server/routes/me/{change-email.post.js → email.put.js} +9 -10
  29. package/dist/runtime/server/routes/me/{change-password.post.js → password.put.js} +4 -5
  30. package/dist/runtime/server/routes/me/profile.patch.js +22 -0
  31. package/dist/runtime/server/schemas.d.ts +7 -0
  32. package/dist/runtime/server/schemas.js +4 -0
  33. package/dist/runtime/server/user-store.js +5 -3
  34. package/dist/runtime/server/utils/admin.d.ts +15 -3
  35. package/dist/runtime/server/utils/admin.js +16 -15
  36. package/dist/runtime/server/utils/dto.d.ts +19 -0
  37. package/dist/runtime/server/utils/dto.js +22 -0
  38. package/dist/runtime/server/utils/email.d.ts +18 -0
  39. package/dist/runtime/server/utils/email.js +18 -0
  40. package/dist/runtime/utils/api.d.ts +33 -0
  41. package/dist/runtime/utils/api.js +32 -0
  42. package/dist/runtime/utils/index.d.ts +3 -1
  43. package/dist/runtime/utils/index.js +1 -0
  44. package/dist/types.d.mts +1 -1
  45. package/package.json +16 -11
  46. package/dist/runtime/server/routes/me/profile.post.js +0 -17
  47. /package/dist/runtime/server/routes/me/{change-email.post.d.ts → email.put.d.ts} +0 -0
  48. /package/dist/runtime/server/routes/me/{change-password.post.d.ts → password.put.d.ts} +0 -0
  49. /package/dist/runtime/server/routes/me/{profile.post.d.ts → profile.patch.d.ts} +0 -0
package/dist/module.d.mts CHANGED
@@ -33,6 +33,26 @@ type ModuleOptions = {
33
33
  mcp?: boolean;
34
34
  };
35
35
  };
36
+ /** A user as the users admin API returns it (`GET /api/admin/users/:id`, create and edit): an allowlist, never the row. */
37
+ type AdminUserDto = {
38
+ id: number;
39
+ name: string;
40
+ email: string;
41
+ /** Only when an authorization module added the `role` column. */
42
+ role?: string;
43
+ avatar: string | null;
44
+ emailVerifiedAt: string | null;
45
+ lastLoginAt: string | null;
46
+ createdAt: string;
47
+ };
48
+ /** The signed-in user's own profile, as the self-service routes return it. */
49
+ type ProfileDto = {
50
+ id: number;
51
+ name: string;
52
+ email: string;
53
+ avatar: string | null;
54
+ emailVerifiedAt: string | null;
55
+ };
36
56
 
37
57
  declare module 'nitropack' {
38
58
  interface NitroRuntimeHooks {
@@ -58,4 +78,4 @@ declare module 'nuxt/schema' {
58
78
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
59
79
 
60
80
  export { _default as default };
61
- export type { ModuleOptions, PublicModuleOptions };
81
+ export type { AdminUserDto, ModuleOptions, ProfileDto, PublicModuleOptions };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/users",
3
3
  "configKey": "users",
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { defineNuxtModule, createResolver, addServerImportsDir, addServerHandler, hasNuxtModule } from '@nuxt/kit';
2
- import { registerTailwindSource, registerLocales, registerDatabaseTable, inlineModuleRuntime, moduleApiUrl, addModulePages, resolvePagePath, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
1
+ import { defineNuxtModule, createResolver, addServerImportsDir, hasNuxtModule } from '@nuxt/kit';
2
+ import { registerTailwindSource, registerLocales, registerDatabaseTable, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
3
  import { setAuthUserStore, addAuthScope } from '@frigear-nu/auth/utils';
4
4
 
5
5
  const module$1 = defineNuxtModule({
@@ -51,22 +51,18 @@ const module$1 = defineNuxtModule({
51
51
  nuxt.hook("notify:email:templates", (sources) => sources.push({ dir: resolver.resolve("./runtime/emails") }));
52
52
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
53
53
  inlineModuleRuntime(nuxt, resolver);
54
- for (const [path, file] of [
55
- ["me/profile", "profile.post"],
56
- ["me/change-email", "change-email.post"],
57
- ["me/change-password", "change-password.post"]
58
- ]) {
59
- addServerHandler({ route: moduleApiUrl("users", path), method: "post", handler: resolver.resolve(`./runtime/server/routes/me/${file}`) });
60
- }
54
+ const selfRoutes = [
55
+ { method: "patch", path: "me", file: "me/profile.patch" },
56
+ { method: "put", path: "me/email", file: "me/email.put" },
57
+ { method: "put", path: "me/password", file: "me/password.put" }
58
+ ];
61
59
  if (settings.verifyEmailChange) {
62
- for (const [method, path, file] of [
63
- ["get", "email-change", "email-change.get"],
64
- ["post", "email-change/confirm", "email-change-confirm.post"],
65
- ["get", "email-change/revert", "email-change-revert.get"],
66
- ["post", "email-change/revert", "email-change-revert.post"]
67
- ]) {
68
- addServerHandler({ route: moduleApiUrl("users", path), method, handler: resolver.resolve(`./runtime/server/routes/me/${file}`) });
69
- }
60
+ selfRoutes.push(
61
+ { method: "get", path: "email-change", file: "me/email-change.get" },
62
+ { method: "post", path: "email-change/confirm", file: "me/email-change-confirm.post" },
63
+ { method: "get", path: "email-change/revert", file: "me/email-change-revert.get" },
64
+ { method: "post", path: "email-change/revert", file: "me/email-change-revert.post" }
65
+ );
70
66
  nuxt.hook("modules:done", () => {
71
67
  if (!hasNuxtModule("@nuxt/ui", nuxt)) {
72
68
  console.warn("[@frigear-nu/users] `settings.verifyEmailChange` is on, but `@nuxt/ui` is not installed: add your own pages at `/auth/verify-email-change` and `/auth/revert-email-change` (see the users module docs).");
@@ -82,6 +78,7 @@ const module$1 = defineNuxtModule({
82
78
  schema: (dialect) => `./runtime/db/email-changes.${dialect}`
83
79
  });
84
80
  }
81
+ addModuleRoutes(resolver, selfRoutes, { base: "/api/users" });
85
82
  if (settings.mcp === true) {
86
83
  const { addMcpDefinitions } = await import('@frigear-nu/mcp/utils');
87
84
  addAuthScope(nuxt, { name: "profile:read", description: "Read your own name, email and role (MCP)" });
@@ -96,19 +93,17 @@ const module$1 = defineNuxtModule({
96
93
  }
97
94
  const adminPagePath = withAdmin && withAdminShell ? resolvePagePath(adminOptions.page ?? true, (await import('@frigear-nu/admin/utils')).adminRoute(nuxt, "users")) : void 0;
98
95
  if (withAdmin) {
99
- for (const [method, path, file] of [
100
- ["get", "/api/admin/users", "users.get"],
101
- ["post", "/api/admin/users", "users.post"],
102
- ["get", "/api/admin/users/new", "new.get"],
103
- ["get", "/api/admin/users/stats", "stats.get"],
104
- ["get", "/api/admin/users/roles", "roles.get"],
105
- ["get", "/api/admin/users/:id", "user.get"],
106
- ["patch", "/api/admin/users/:id", "user.patch"],
107
- ["delete", "/api/admin/users/:id", "user.delete"],
108
- ["post", "/api/admin/users/:id/resend", "user-resend.post"]
109
- ]) {
110
- addServerHandler({ route: path, method, handler: resolver.resolve(`./runtime/server/routes/admin/${file}`) });
111
- }
96
+ addModuleRoutes(resolver, [
97
+ { method: "get", path: "", file: "admin/users.get" },
98
+ { method: "post", path: "", file: "admin/users.post" },
99
+ { method: "get", path: "new", file: "admin/new.get" },
100
+ { method: "get", path: "stats", file: "admin/stats.get" },
101
+ { method: "get", path: "roles", file: "admin/roles.get" },
102
+ { method: "get", path: ":id", file: "admin/user.get" },
103
+ { method: "patch", path: ":id", file: "admin/user.patch" },
104
+ { method: "delete", path: ":id", file: "admin/user.delete" },
105
+ { method: "post", path: ":id/resend", file: "admin/user-resend.post" }
106
+ ], { base: "/api/admin/users" });
112
107
  if (adminPagePath) {
113
108
  addModulePages("@frigear-nu/users", resolver, [
114
109
  { name: "users-admin", path: adminPagePath, file: "./runtime/app/pages/admin.vue" },
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { usersApi } from "../../utils/api";
2
3
  import { z } from "zod";
3
4
  defineOptions({ name: "UsersUserCreateSlideover" });
4
5
  const props = defineProps({
@@ -19,7 +20,7 @@ const roleLabel = (value) => t(`admin.roleNames.${value}`, value.charAt(0).toUpp
19
20
  const roleItems = computed(() => (props.roles ?? []).map((value) => ({ label: roleLabel(value), value })));
20
21
  async function save(event) {
21
22
  const created = await run(
22
- () => $fetch("/api/admin/users", {
23
+ () => $fetch(usersApi.admin.users, {
23
24
  method: "POST",
24
25
  body: { ...event.data, role: roleItems.value.length && event.data.role ? event.data.role : void 0 }
25
26
  }),
@@ -14,7 +14,7 @@ export interface UserMenuOptions {
14
14
  };
15
15
  }
16
16
  /**
17
- * Everything staff do to a user: `create` (a slideover), `remove` (confirm, toast, refresh) and `menu(user)` for the
17
+ * Everything staff do to a user: `create` (a slideover, then the new user's page), `remove` (confirm, toast, refresh) and `menu(user)` for the
18
18
  * `RowMenu` of the list rows and the detail heading, ordered Open, sign-in link, extras, then Delete in its own group.
19
19
  */
20
20
  export declare function useUserActions(): {
@@ -1,5 +1,6 @@
1
1
  import UserCreateSlideover from "../components/UserCreateSlideover.vue";
2
2
  import { ADMIN_USERS_KEY } from "../utils/admin-user.js";
3
+ import { usersApi } from "../../utils/api.js";
3
4
  export function useUserActions() {
4
5
  const t = useModuleT("users");
5
6
  const overlay = useOverlay();
@@ -10,7 +11,9 @@ export function useUserActions() {
10
11
  const listPath = computed(() => localize(adminPage.replace(/\/+$/, "")));
11
12
  const userPath = (id) => `${listPath.value}/${id}`;
12
13
  async function create(options = {}) {
13
- return await overlay.create(UserCreateSlideover).open({ roles: options.roles ?? [] });
14
+ const created = await overlay.create(UserCreateSlideover).open({ roles: options.roles ?? [] });
15
+ if (created) await navigateTo(userPath(created.id));
16
+ return created;
14
17
  }
15
18
  async function remove(user, options = {}) {
16
19
  const confirmed = await confirm({
@@ -21,7 +24,7 @@ export function useUserActions() {
21
24
  });
22
25
  if (!confirmed) return false;
23
26
  const done = await run(
24
- () => $fetch(`/api/admin/users/${user.id}`, { method: "DELETE" }).then(() => true),
27
+ () => $fetch(usersApi.admin.user(user.id), { method: "DELETE" }).then(() => true),
25
28
  { success: t("admin.deleted", "User deleted.") }
26
29
  );
27
30
  if (!done) return false;
@@ -31,7 +34,7 @@ export function useUserActions() {
31
34
  }
32
35
  async function resend(user) {
33
36
  const sent = await run(
34
- () => $fetch(`/api/admin/users/${user.id}/resend`, { method: "POST" }).then(() => true),
37
+ () => $fetch(usersApi.admin.resend(user.id), { method: "POST" }).then(() => true),
35
38
  { success: t("admin.resent", "Sign-in link sent.") }
36
39
  );
37
40
  return !!sent;
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { usersApi } from "../../utils/api";
2
3
  import OverviewTab from "../tabs/Overview.vue";
3
4
  import { useUserActions } from "../composables/useUserActions";
4
5
  defineOptions({ name: "UsersAdminUserPage" });
@@ -6,7 +7,8 @@ const t = useModuleT("users");
6
7
  const route = useRoute();
7
8
  const actions = useUserActions();
8
9
  const id = computed(() => route.params.id);
9
- const { data: user, refresh, error } = await useFetch(() => `/api/admin/users/${id.value}`);
10
+ const { data: user, refresh, error } = await useFetch(() => usersApi.admin.user(id.value));
11
+ const forbidden = computed(() => [401, 403].includes(error.value?.statusCode ?? 0));
10
12
  const Tabs = resolveComponent("WidgetTabs");
11
13
  const tabs = typeof Tabs === "string" ? void 0 : Tabs;
12
14
  const menu = computed(() => user.value ? actions.menu(user.value, {
@@ -21,7 +23,14 @@ const menu = computed(() => user.value ? actions.menu(user.value, {
21
23
  <template>
22
24
  <div class="flex flex-col gap-4">
23
25
  <UEmpty
24
- v-if="error || !user"
26
+ v-if="error && error.statusCode !== 404"
27
+ :icon="forbidden ? 'i-lucide-lock' : 'i-lucide-circle-alert'"
28
+ :title="forbidden ? t('admin.forbidden', 'You do not have access to users') : t('admin.detail.loadFailed', 'The user could not be loaded')"
29
+ :description="errorMessage(error, '')"
30
+ :actions="forbidden ? [] : [{ label: t('admin.tryAgain', 'Try again'), icon: 'i-lucide-rotate-ccw', color: 'neutral', variant: 'outline', onClick: () => refresh() }]"
31
+ />
32
+ <UEmpty
33
+ v-else-if="error || !user"
25
34
  icon="i-lucide-user-x"
26
35
  :title="t('admin.detail.notFound', 'User not found')"
27
36
  :description="t('admin.detail.notFoundHint', 'It may have been deleted.')"
@@ -34,9 +43,9 @@ const menu = computed(() => user.value ? actions.menu(user.value, {
34
43
  :breadcrumb="[{ label: t('admin.title', 'Users'), to: actions.listPath.value }, { label: user.name }]"
35
44
  >
36
45
  <template #badge>
37
- <UBadge
38
- :color="user.emailVerifiedAt ? 'success' : 'warning'"
39
- variant="subtle"
46
+ <StatusBadge
47
+ :status="user.emailVerifiedAt ? 'verified' : 'unverified'"
48
+ :colors="{ verified: 'success', unverified: 'warning' }"
40
49
  :label="user.emailVerifiedAt ? t('admin.filters.verified', 'Verified') : t('admin.filters.unverified', 'Unverified')"
41
50
  />
42
51
  </template>
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { usersApi } from "../../utils/api";
2
3
  import { ADMIN_USERS_KEY } from "../utils/admin-user";
3
4
  import { useUserActions } from "../composables/useUserActions";
4
5
  defineOptions({ name: "UsersAdminPage" });
@@ -11,20 +12,22 @@ const { page, pageSize, search, sort: sortState, filters, query, filtered, reset
11
12
  });
12
13
  const sort = useTableSort(null, sortState);
13
14
  const { sorting } = sort;
14
- const { data, status } = await useFetch("/api/admin/users", {
15
+ const { data, status, error, refresh } = await useFetch(usersApi.admin.users, {
15
16
  key: ADMIN_USERS_KEY,
16
- query,
17
- default: () => ({ items: [], total: 0, page: 1, pageSize: 20, hasRoles: false, hasSubscriptions: false, roles: [] })
17
+ query
18
18
  });
19
- const hasRoles = computed(() => data.value.hasRoles);
20
- const hasSubscriptions = computed(() => data.value.hasSubscriptions);
19
+ const rows = computed(() => data.value?.items ?? []);
20
+ const hasRoles = computed(() => data.value?.hasRoles ?? false);
21
+ const hasSubscriptions = computed(() => data.value?.hasSubscriptions ?? false);
22
+ const roles = computed(() => data.value?.roles ?? []);
23
+ const forbidden = computed(() => [401, 403].includes(error.value?.statusCode ?? 0));
21
24
  const roleLabel = (value) => t(`admin.roleNames.${value}`, value.charAt(0).toUpperCase() + value.slice(1));
22
- const roleItems = computed(() => data.value.roles.map((value) => ({ label: roleLabel(value), value })));
25
+ const roleItems = computed(() => roles.value.map((value) => ({ label: roleLabel(value), value })));
23
26
  const roleFilterItems = computed(() => [{ label: t("admin.filters.allRoles", "All roles"), value: "all" }, ...roleItems.value]);
24
27
  const pending = computed(() => status.value === "pending");
25
- const loading = computed(() => pending.value && !data.value.items.length);
26
- const refreshing = computed(() => pending.value && !!data.value.items.length);
27
- const UBadge = resolveComponent("UBadge");
28
+ const loading = computed(() => pending.value && !data.value);
29
+ const refreshing = computed(() => pending.value && !!data.value);
30
+ const StatusBadge = resolveComponent("StatusBadge");
28
31
  const TableIdentity = resolveComponent("TableIdentity");
29
32
  const RowMenu = resolveComponent("RowMenu");
30
33
  const dateCell = (value) => value ? h("time", { datetime: value, title: format.dateTime(value), class: "tabular-nums" }, format.date(value)) : emptyCell();
@@ -45,18 +48,18 @@ const columns = computed(() => [
45
48
  }] : [],
46
49
  ...hasSubscriptions.value ? [{
47
50
  id: "subscription",
48
- header: t("admin.subscription", "Subscription"),
51
+ header: t("admin.subscription", "Membership"),
49
52
  cell: ({ row }) => {
50
53
  const subscription = row.original.subscription;
51
- return subscription ? h(UBadge, { variant: "subtle", color: statusColor(subscription.status), label: subscription.planKey ?? subscription.status }) : emptyCell();
54
+ return subscription ? h(StatusBadge, { status: subscription.status, label: subscription.planKey ?? subscription.status }) : emptyCell();
52
55
  }
53
56
  }] : [],
54
57
  {
55
58
  id: "verified",
56
59
  header: t("admin.verified", "Verified"),
57
- cell: ({ row }) => h(UBadge, {
58
- variant: "subtle",
59
- color: row.original.emailVerifiedAt ? "success" : "neutral",
60
+ cell: ({ row }) => h(StatusBadge, {
61
+ status: row.original.emailVerifiedAt ? "verified" : "unverified",
62
+ colors: { verified: "success" },
60
63
  label: row.original.emailVerifiedAt ? t("admin.filters.verified", "Verified") : t("admin.filters.unverified", "Unverified")
61
64
  })
62
65
  },
@@ -81,10 +84,7 @@ const verifiedOptions = computed(() => [
81
84
  function openUser(_event, row) {
82
85
  return navigateTo(actions.userPath(row.original.id));
83
86
  }
84
- async function addUser() {
85
- const created = await actions.create({ roles: hasRoles.value ? data.value.roles : [] });
86
- if (created) await navigateTo(actions.userPath(created.id));
87
- }
87
+ const addUser = () => actions.create({ roles: hasRoles.value ? roles.value : [] });
88
88
  </script>
89
89
 
90
90
  <template>
@@ -92,72 +92,82 @@ async function addUser() {
92
92
  <PageHeading :title="t('admin.title', 'Users')">
93
93
  <template #actions>
94
94
  <UButton
95
- icon="i-lucide-user-plus"
95
+ icon="i-lucide-plus"
96
96
  :label="t('admin.create', 'Add user')"
97
97
  @click="addUser"
98
98
  />
99
99
  </template>
100
100
  </PageHeading>
101
101
 
102
- <PageToolbar>
103
- <UInput
104
- v-model="search"
105
- class="w-full max-w-sm"
106
- icon="i-lucide-search"
107
- :loading="pending"
108
- :placeholder="t('admin.search', 'Search name, email or role...')"
109
- />
110
- <USelect
111
- v-model="filters.verified"
112
- :items="verifiedOptions"
113
- class="w-40"
114
- />
115
- <USelect
116
- v-if="hasRoles"
117
- v-model="filters.role"
118
- :items="roleFilterItems"
119
- class="w-48"
120
- icon="i-lucide-shield"
121
- />
122
- <UButton
123
- v-if="filtered"
124
- variant="ghost"
125
- color="neutral"
126
- icon="i-lucide-x"
127
- :label="t('admin.filters.clear', 'Clear filters')"
128
- @click="reset"
129
- />
130
- </PageToolbar>
102
+ <UEmpty
103
+ v-if="error && !data"
104
+ :icon="forbidden ? 'i-lucide-lock' : 'i-lucide-circle-alert'"
105
+ :title="forbidden ? t('admin.forbidden', 'You do not have access to users') : t('admin.loadFailed', 'Users could not be loaded')"
106
+ :description="errorMessage(error, '')"
107
+ :actions="forbidden ? [] : [{ label: t('admin.tryAgain', 'Try again'), icon: 'i-lucide-rotate-ccw', color: 'neutral', variant: 'outline', onClick: () => refresh() }]"
108
+ />
131
109
 
132
- <TableCard
133
- :loading="loading"
134
- :refreshing="refreshing"
135
- >
136
- <UTable
137
- v-model:sorting="sorting"
138
- :data="data.items"
139
- :columns="columns"
140
- :sorting-options="{ manualSorting: true }"
141
- :ui="tableUi({}, { sticky: true })"
142
- sticky
143
- @select="openUser"
110
+ <template v-else>
111
+ <PageToolbar>
112
+ <UInput
113
+ v-model="search"
114
+ class="w-full max-w-sm"
115
+ icon="i-lucide-search"
116
+ :loading="pending"
117
+ :placeholder="t('admin.search', 'Search name, email or role...')"
118
+ />
119
+ <USelect
120
+ v-model="filters.verified"
121
+ :items="verifiedOptions"
122
+ class="w-40"
123
+ />
124
+ <USelect
125
+ v-if="hasRoles"
126
+ v-model="filters.role"
127
+ :items="roleFilterItems"
128
+ class="w-48"
129
+ icon="i-lucide-shield"
130
+ />
131
+ <UButton
132
+ v-if="filtered"
133
+ variant="ghost"
134
+ color="neutral"
135
+ icon="i-lucide-x"
136
+ :label="t('admin.filters.clear', 'Clear filters')"
137
+ @click="reset"
138
+ />
139
+ </PageToolbar>
140
+
141
+ <TableCard
142
+ :loading="loading"
143
+ :refreshing="refreshing"
144
144
  >
145
- <template #empty>
146
- <UEmpty
147
- icon="i-lucide-users"
148
- variant="naked"
149
- :title="t('admin.empty', 'No users match')"
150
- :actions="[filtered ? { label: t('admin.filters.clear', 'Clear filters'), color: 'neutral', variant: 'outline', onClick: reset } : { label: t('admin.create', 'Add user'), icon: 'i-lucide-user-plus', onClick: addUser }]"
145
+ <UTable
146
+ v-model:sorting="sorting"
147
+ :data="rows"
148
+ :columns="columns"
149
+ :sorting-options="{ manualSorting: true }"
150
+ :ui="tableUi({}, { sticky: true })"
151
+ sticky
152
+ @select="openUser"
153
+ >
154
+ <template #empty>
155
+ <UEmpty
156
+ icon="i-lucide-users"
157
+ variant="naked"
158
+ :title="t('admin.empty', 'No users match')"
159
+ :actions="[filtered ? { label: t('admin.filters.clear', 'Clear filters'), color: 'neutral', variant: 'outline', onClick: reset } : { label: t('admin.create', 'Add user'), icon: 'i-lucide-plus', onClick: addUser }]"
160
+ />
161
+ </template>
162
+ </UTable>
163
+ <template #footer>
164
+ <TablePagination
165
+ v-model:page="page"
166
+ v-model:page-size="pageSize"
167
+ :total="data?.total ?? 0"
151
168
  />
152
169
  </template>
153
- </UTable>
154
- <template #footer>
155
- <TablePagination
156
- v-model:page="page"
157
- v-model:page-size="pageSize"
158
- :total="data.total"
159
- />
160
- </template>
161
- </TableCard>
170
+ </TableCard>
171
+ </template>
162
172
  </div>
163
173
  </template>
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { usersApi } from "../../utils/api";
2
3
  defineOptions({ name: "UsersRevertEmailChangePage" });
3
4
  const t = useModuleT("users.emailChange");
4
5
  const route = useRoute();
@@ -6,7 +7,7 @@ const { fetch: refreshSession } = useUserSession();
6
7
  const loginPath = useAuthPages().login;
7
8
  const passwordReset = useRuntimeConfig().public.authentication?.passwordReset === true;
8
9
  const code = computed(() => typeof route.query.code === "string" ? route.query.code : "");
9
- const { data: preview, error: previewError } = await useFetch("/api/users/email-change/revert", {
10
+ const { data: preview, error: previewError } = await useFetch(usersApi.emailChangeRevert, {
10
11
  query: { code },
11
12
  immediate: !!code.value
12
13
  });
@@ -22,7 +23,7 @@ async function onRevert() {
22
23
  reverting.value = true;
23
24
  error.value = null;
24
25
  try {
25
- const result = await $fetch("/api/users/email-change/revert", {
26
+ const result = await $fetch(usersApi.emailChangeRevert, {
26
27
  method: "POST",
27
28
  body: { code: code.value }
28
29
  });
@@ -1,4 +1,5 @@
1
1
  <script setup>
2
+ import { usersApi } from "../../utils/api";
2
3
  defineOptions({ name: "UsersVerifyEmailChangePage" });
3
4
  const t = useModuleT("users.emailChange");
4
5
  const route = useRoute();
@@ -6,7 +7,7 @@ const { loggedIn, user, clear, fetch: refreshSession } = useUserSession();
6
7
  const loginPath = useAuthPages().login;
7
8
  const profilePath = useRuntimeConfig().public.users?.profilePath;
8
9
  const code = computed(() => typeof route.query.code === "string" ? route.query.code : "");
9
- const { data: preview, error: previewError } = await useFetch("/api/users/email-change", {
10
+ const { data: preview, error: previewError } = await useFetch(usersApi.emailChange, {
10
11
  query: { code },
11
12
  immediate: !!code.value,
12
13
  // Signing out (wrong account) changes who may confirm.
@@ -33,7 +34,7 @@ async function onConfirm() {
33
34
  confirming.value = true;
34
35
  error.value = null;
35
36
  try {
36
- const result = await $fetch("/api/users/email-change/confirm", {
37
+ const result = await $fetch(usersApi.emailChangeConfirm, {
37
38
  method: "POST",
38
39
  body: { code: code.value }
39
40
  });