Content

Documents

Files in nested folders, stored in NuxtHub Blob, where who may see each file or folder is a grant list that follows its folder unless it has its own.

Documents are the files people need: the handbook, the bar guide, the shift overview, the minutes of a coordinator meeting. Staff upload them under Admin → Documents, put them in folders and decide who may see each one. Signed-in people browse what they may see at /dashboard/documents and download it.

The package is @frigear-nu/documents. Who may see a folder or a file is a grant list (Auth's record audiences): public, signed-in, a role, a team, an operation, a plan, whatever kinds your app has. There is no other access model: no groups, no shares.

What you get

  • Nested folders with files in them, each with a title and description in every language and an icon.
  • Grant inheritance. A folder or a file without a list of its own follows its folder; a folder hides everything in it from people who cannot see the folder.
  • A browse page in the signed-in hub of Dashboard (/dashboard/documents): folders open in place, files download.
  • A staff page (with Admin, /admin/documents): browse every folder, add folders, upload, edit, move, replace and delete, with the grants editor ("Same as the folder", or a list of its own).
  • Safe downloads. Uploads are typed by their bytes, downloads are attachments with nosniff, and only files that are public the whole way down are cached publicly.
ServerClientMobile
Installed for you:Auth, UI and Module Kit; NuxtHub Blob is turned on. You add:@nuxthub/core, and @nuxt/ui for the pages. Optional:Dashboard for the browse page, Admin for the staff page, Menu for the menu entries.

Quick setup

Install documents

pnpm add @frigear-nu/documents @nuxthub/core

Add it to nuxt.config.ts

List Dashboard, Admin and Menu before documents, so the pages and the menu entries register.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxthub/core', '@frigear-nu/dashboard', '@frigear-nu/admin', '@frigear-nu/documents'],
})

Generate the migration

Without a migration the documents table does not exist, and every request to it fails.
pnpm db:generate

Bind Blob in production

On Cloudflare, files go to R2 through NuxtHub's BLOB binding. Configure hub.blob for production as you do for the other modules that store files.

What you should see: an admin opens /admin/documents, adds a folder that one role can see and uploads a PDF into it. Someone with that role finds the folder at /dashboard/documents and downloads the PDF; anybody else sees neither.

Options

nuxt.config.ts
export default defineNuxtConfig({
  documents: {
    settings: {
      pages: {
        // `true` (the default) is `<hub>/documents`; a string is a path of its own; `false` turns it off.
        browse: true,
        // `true` (the default, with Admin) is `/admin/documents`; `false` turns it off.
        admin: true,
      },
      // The largest upload, in bytes (25 MB by default). Uploads are read into memory.
      maxFileBytes: 25 * 1024 * 1024,
    },
  },
})

Without the dashboard hub there is no browse page unless pages.browse is a path; that page is then guarded for signed-in people (with Authorization).

Who sees what

Every document stores grants: a grant list, or null.

grantsWhat applies
a listThat list: any one grant admits, [] admits nobody but managers.
nullThe same as its folder: the nearest folder above it with a list. At the top level, nobody but managers.

A document is visible when the list that applies to it and the list that applies to every folder above it admit the reader. A file can narrow its folder but never widen it: a public file in a crew folder is for the crew only.

  • Anonymous visitors see a document only when every list on the way holds public. Only those downloads are cached publicly (cache-control: public, max-age=300); everything else is private, no-store.
  • A folder whose parent is missing (or a loop) hides everything in it.
  • People who hold documents:manage see every document, also those whose list is empty.
  • A hidden document answers 404, the same as one that does not exist.
  • A new document without grants follows its folder; one at the top level starts with [] (managers only).

Reads go through grantsCanRead(event, 'documents:read', { grants }) on the list that applies, so a token without the documents scope reads public documents only. The documents:read policy evaluates the list with grantsMatch; the route walks the folders.

Uploads

A file is accepted when its extension is one of PDF, PNG, JPEG, WebP, GIF, Word, Excel, PowerPoint (both the current and the old formats), OpenDocument, ZIP, TXT, CSV or Markdown and its bytes match that extension. The stored type is the one read from the bytes, never the browser's. Anything else is refused with 415 unsupported_media_type. A request larger than maxFileBytes is refused from its content-length before it is read (413 file_too_large).

Files are stored in Blob under documents/<id>/ with a random suffix, so a replaced file gets a new path and the old one is deleted. When the database write fails, the stored file is deleted again. Deleting a folder deletes everything in it, with the files.

Permissions

PermissionWho holds itWhat it allows
documents:manageadminThe staff routes and page; seeing every document.
documents:readEvery signed-in user (implicit)Browsing and downloading the documents their grants admit. Scope documents.

Routes

Path builders: documentsApi from @frigear-nu/documents/api.

RouteWhat it does
GET /api/documents?parent=<id>The folder (null at the top level), the folders on the way down to it (breadcrumb) and the visible items in it. 404 for a hidden folder.
GET /api/documents/:id/downloadThe file as an attachment. 404 when hidden or missing.
GET /api/admin/documentsEvery folder and file with grants, effectiveGrants and public.
POST /api/admin/documents/foldersA new folder: { title, description?, icon?, parentId?, sortOrder?, grants? }.
POST /api/admin/documents/filesAn upload: multipart with a file part and a meta part holding the folder fields as JSON (title defaults to the file name).
PATCH /api/admin/documents/:idAny of the fields; parentId moves it (never into itself), grants: null makes it follow its folder.
PUT /api/admin/documents/:id/fileReplaces the stored file of a file (multipart, file).
DELETE /api/admin/documents/:idDeletes a file, or a folder with everything in it.

Database

One table, documents: id (doc_…), parentId (the folder, deleted with it), kind (folder or file), title and description (translated JSON), icon, sortOrder, grants (JSON, nullable), and for files pathname (in Blob, never sent to clients), filename, contentType and size, plus createdBy, createdAt and updatedAt.

Copyright © 2026