Admin
The admin is the app editors work in, at /admin by default. Everything you change about it sits in the admin object of defineCms(). This page covers how it looks and where things are: branding, navigation, the admin bar on your site, languages and the path. To add your own inputs, see Custom fields. For your own pages and buttons, see Custom pages and actions.
Branding
The admin shows your logo in the top bar and on the login:
export default defineCms({
// ...
site: { name: "Acme" },
admin: {
logo: { light: "/logo-light.svg", dark: "/logo-dark.svg" },
icon: "/icon.svg",
},
});
{ header: "/logo-wide.svg", login: "/logo.svg" }. A place without a logo shows the icon and the name.icon, then the favicon.svg, .ico or .png in your public folder, then the Tenon icon.- The name is
site.name, not anadminoption. The admin, the admin bar, emails and passkeys show it. { light, dark }follows the admin's theme.- The admin links the files and does not bundle them. Put them in your public folder, like
public/logo.svg, and use the URL/logo.svg.
Navigation
The content menu lists every collection, global, the media library and your own pages. nav decides where an entry shows:
export const posts = defineCollection({
label: "Posts",
nav: { group: "Blog", icon: "newspaper", order: 1 },
fields: {
// ...
},
});
content is the content menu, the default. settings is a card on the Settings page. main is the top bar, next to Content and Visual Editor. none hides the entry.newspaper. A typo is a type error.- Equal orders keep the order you define them in. Sections show in the order of their first entry.
- To move the media library, set
admin.media:{ label: "Files", nav: { group: "Assets", icon: "images" } }.
The Settings page
Globals that editors rarely open belong on the Settings page. Each one is a card there, grouped by group:
export const footer = defineGlobal({
label: "Footer",
nav: { display: "settings", order: 3 },
fields: {
// ...
},
});
The content menu shows Settings under Manage as soon as one entry has display: "settings". The built-in general and seo globals sit there too. See Site settings.
Admin bar
The admin bar is a small bar on your site. Signed-in editors see it on every page, with your logo and name, Edit, the Drafts / Published switch and a button to hide it. Visitors never load it.
- Edit opens the current page in the visual editor.
- The bar hides while you scroll down. Your page's CSS does not reach it.
- In a preview tab, it shows Back to visual editor and an Edit preview switch instead.
admin.adminBar sets where it sits and what it shows:
export default defineCms({
// ...
admin: {
adminBar: {
position: "bottom-right",
items: {
analytics: {
label: "Analytics",
icon: "chart-bar",
href: "https://plausible.io/example.com",
},
perspective: false,
},
},
},
});
positionis one of eight places:top-left,top-center,top-right,center-left,center-right,bottom-left,bottom-center(the default) andbottom-right.falsefor an item removes it. That works for the built-in items too.adminBar: falseturns the bar off.
Items
The key of an item is its id. An item with the id of an existing one replaces it. Each item is one of these:
| Item | Set |
|---|---|
| Link | href: a path like /about, or an http(s) URL |
| Dropdown | children: items by id, one level deep |
| Button | onClick: browser code that runs on click |
| Control | mount: browser code that renders the item |
Every item has a label, and can have an icon and an order. The built-in items are dashboard (order 10), edit (20) and perspective (30). Items without an order come last.
Items that depend on the page
load runs on the server for every page the bar shows on. It gets the user, their cms, the admin locale and the page url. For a link or dropdown, it returns new values for label, icon, href or children, or null to hide the item:
analytics: {
label: "Analytics",
href: "https://plausible.io/example.com",
load: ({ url, user }) =>
user.role === "admin"
? { href: `https://plausible.io/example.com?page=${encodeURIComponent(new URL(url).pathname)}` }
: null,
},
urlcomes from the browser. Never trust it, and never fetch it.- A
loadthat throws is logged, and its item is left out. The rest of the bar stays.
Buttons and controls
onClick and mount are browser code, from a .client.ts module. For a button or control, load returns any JSON, and the code gets it as ctx.data:
import type { AdminBarItemContext, Mount } from "tenoncms/admin";
export const copyUrl = () => navigator.clipboard.writeText(location.href);
export const mountGreeting: Mount<AdminBarItemContext<string>> = (el, ctx) => {
const render = (next: AdminBarItemContext<string>) => (el.textContent = next.data);
el.style.cssText = "font: 500 12px/1 sans-serif; padding: 4px 8px";
render(ctx);
return { update: render, unmount: () => el.replaceChildren() };
};
import { copyUrl, mountGreeting } from "./src/admin/bar.client";
admin: {
adminBar: {
items: {
copy: { label: "Copy URL", icon: "link", onClick: copyUrl },
greeting: { label: "Greeting", mount: mountGreeting, load: ({ user }) => `Hi ${user.name}` },
},
},
},
- The context also has the bar's state, like
perspectiveandsetPerspective(), andtenon.reload()to runloadagain. - The bar sits in a shadow root, so your CSS does not reach it. See Style admin bar items.
- The bar loads on every page of your site. Its modules MUST NOT import CSS, so keep bar code in its own module.
Languages
The admin is localized (only English and German for now). Each user picks their preferred language under Interface language in the user menu. Without a choice, the admin follows the browser.
Every label and description you write takes one string, or one per language:
label: { en: "Posts", de: "Beiträge" },
- A missing language shows English, then the first entry.
- The admin language is separate from the languages of your content. See Localization.
- Validation messages from the server stay English.
Texts in your own code
Fields, pages and bar items get the admin language as ctx.tenon.locale. translator() from tenoncms/admin reads your own message files:
import { translator, type Mount, type PageContext } from "tenoncms/admin";
import de from "./locales/de.json";
import en from "./locales/en.json";
export const mountStats: Mount<PageContext> = (el, ctx) => {
const t = translator({ en, de }, ctx.tenon.locale);
el.textContent = t("stats.count", { n: 3 });
// ...
};
- Keys are dotted paths, and
{n}fills a parameter. A missing key shows English, then the key. - A language switch calls
update(ctx)with the newlocale. - A server
loadgets the language aslocale.
Admin path
The admin runs at /admin. To serve it somewhere else, like /cms, set admin.path:
export default defineCms({
// ...
admin: { path: "/cms" },
});
- and _. It MUST NOT be / or sit under /_tenon.- Invite links,
tenon loginand the admin bar point to the new path. pathMUST be a string or an environment variable, likeprocess.env.ADMIN_PATH ?? "/cms". The build reads it from the file without running it, so a change needs a rebuild.- The HTTP API stays at
/_tenon, wherever the admin is.
TanStack Start serves the admin from a route file, so it needs two more changes:
- Rename
src/routes/admin.$.tstosrc/routes/cms.$.ts, and change the path in it:src/routes/cms.$.tsimport { createFileRoute } from "@tanstack/react-router"; import html from "#tenon/admin-html"; export const Route = createFileRoute("/cms/$")({ server: { handlers: { GET: () => new Response(html, { headers: { "content-type": "text/html; charset=utf-8" } }), }, }, }); - Pass the path to
preview()in the root route, so the admin bar links to it:src/routes/__root.tsxuseEffect(() => preview({ admin: "/cms" }), []);
Then restart the dev server.
Without the admin
admin: false ships no admin. Use it when editors work somewhere else and your site only reads content.
- The HTTP API under
/_tenonworks as before. - The admin bar, custom fields, pages, actions and
tenon loginare gone. cms.users.invite()needs aurl, because there is no admin page to link to.- In TanStack Start, remove
tenonAdmin()and the admin route.
Related resources
- Custom fields: your own inputs, and how browser code reaches the admin.
- Custom pages and actions: your own views and server buttons.
- Collections and globals:
label,descriptionandnavon each entry. - Live preview: the visual editor that Edit opens.