MongocampUsers
Full CRUD table for managing users — create, edit (roles via a transfer listbox, password change), and delete, all via modal dialogs. Includes a server-side debounced search input and sortable column headers.
Usage
vue
<template>
<MongocampUsers />
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
userIdType | 'email' | 'text' | 'email' | The new user's id in Add User: 'email' labels it Email and checks the address, 'text' labels it User and takes any MongoCamp user id. Like MongocampLogin's prop of the same name. |
hideHeading | boolean | false | Hide the component's own heading, e.g. when the page around it already shows a title. The toolbar stays. |
hideRefresh | boolean | false | Hide the component's own reload button, e.g. when the page calls the exposed refresh() from its own header. |
In a page with its own header
The component can hand its toolbar to the page around it:
refresh()is exposed — call it through a template ref from your own reload button, and sethideRefreshto drop the built-in one.toolbarslot — your own buttons, placed beside the built-in ones.changedevent — emitted after a user was added, edited, disabled/enabled or deleted, or an API key was regenerated, once the component has reloaded. Never on a failed or cancelled action, never on a plain reload.
vue
<script setup lang="ts">
const list = useTemplateRef<{ refresh: () => void }>('list')
</script>
<template>
<header>
<h1>My title</h1>
<UButton icon="i-lucide-refresh-cw" @click="list?.refresh()" />
</header>
<MongocampUsers ref="list" hide-heading hide-refresh @changed="reloadOtherLists">
<template #toolbar>
<UButton>Mine</UButton>
</template>
</MongocampUsers>
</template>Behavior
- List — fetched via
useMongocampAdmin().listUsers(filter), debounced 300ms on the search input. - Add — FormKit modal for
userId,password, optional Display name and E-mail address (server 3.0), and roles (nuxtUIListboxindisplayMode: 'transfer'). - Edit — display name, e-mail address, E-mail address verified, roles and a new password. Changed fields go first in one
PATCH(updateUser; nothing changed ⇒ no request, a cleared field is removed); an address another user has (409, code4093) keeps the dialog open with the reason and changes no roles. - Server 3.0 user fields in the table — display name and e-mail under the user id, a State column (Disabled, e-mail Not verified) and a sortable Last login column (Never without one).
- Disable / Enable — the user icon on every row but your own (in proxy mode: the api key's user). Disabling is confirmed — the user can no longer log in (
401, code4013) and every token and session of the user stops working at once; a refusal keeps the dialog open with the reason. Enabling needs no confirmation. Both reload the list, toast and emitchanged. - Invite User (server 3.0 with
AUTH_REGISTRATION=invite; propinviteunset = follow the server — 3.1 announcesauthRegistration:invitein its capabilities —,true/falseforce it) — e-mail address and roles ⇒useMongocampAdmin().inviteUser. The server mails a registration link (/register?token=, seeMongocampRegister) through the app'smongocamp:auth:mailhook; the user appears in the list only after registering, so nothing is reloaded andchangedis not emitted. A refusal (anotherAUTH_REGISTRATIONis a400naming the setting) stays in the dialog. - Delete — confirmation modal before calling
deleteUser. If the server refuses, the dialog stays open and shows why (network/session, permission, or the server's own message) so you can try again or cancel; the list is only reloaded after a successful delete. A user that is already gone (404, deleted elsewhere) counts as deleted. - Details — the info icon opens a read-only side drawer with the user's Admin/User badge (and Disabled), display name, e-mail address with its verified state, last login, assigned roles and effective grants (
MongocampGrantList). It is rendered from the list row —getUserreturns exactly the same object, so no extra request is made — on a copy, so the row is never touched. The user's API key is deliberately not shown. - Regenerate API key — the key icon (not shown on your own row — use
MongocampAccountfor your own key) opens a confirmation that says the user's current key stops working immediately. After confirming, the new key is shown once with a copy button; closing the dialog discards it — it is never stored or logged, and reopening starts from the confirmation again. A refused call (for example403) keeps the dialog open with the reason and shows no key. The user list is reloaded after a success. CallsuseMongocampAdmin().regenerateUserApiKey. - Sorting — clickable column headers via
sortHeader(). - Paging — 25 rows a page with a pager below the table once there are more. The table pages its sorted rows, so a header sort orders the whole list; the selection is kept across pages and select-all selects the page on screen. A new search starts at page 1; a shorter list after a delete never leaves you past the last page.
- Bulk delete — a checkbox column (with select-all) and a selection bar; confirming deletes the selected users a few at a time via
deleteUser(MongocampBulkDelete). The signed-in user can't be selected, not even through select-all (the checkbox is disabled and says why), since deleting yourself would end your own session — for the same reason the delete button on your own row is disabled too, with the same explanation. In server proxy mode "your own row" is the user of the server's api key (useMongocampSelf): no delete, no Regenerate API key, no Edit (its roles), not selectable — either would cut off the proxy; until the server has answered who that is, delete and regenerate are disabled on every row. The selection is cleared on every reload; failures are reported and stay selected. - Errors / empty — a failed load shows
MongocampErrorAlertwith retry; no rows shows an empty state.