User menu
The signed-in user sits at the bottom of the sidebar, and on a phone at the top right of the top bar, where the menu opens as a sheet from the bottom. Clicking them opens a menu with their name and email, which link to their account, “Set a status” in an app with status, the app’s own pages, the theme switch, and “Sign out”. Account pages (organization, billing, users) and help links belong here rather than among the working resources.
“Sign out” asks first, in the app’s dialog, in a browser and in an app alike. Once the person has signed out, the shell dispatches a protobase:signed-out event on window (signedOutEvent of @protobase/ui), and posts { type: 'protobase:signed-out' } to a page that frames it, for a host app around the page, such as one that keeps its own copy of the person’s session and ends it too.
Export one userMenu(...) from config/index.ts:
// tests/apps/erp/config/user-menu.ts, re-exported from config/index.tsimport { userMenu } from '@protobase/schema'
export const accountMenu = userMenu((m) => [ m.resource('organizations', { label: 'Organization', icon: 'building' }), m.page('accounts', { label: 'Users', icon: 'users' }), m.link('Documentation', 'https://docs.protobase.net', { icon: 'book-open' }),])| Item | Does |
|---|---|
m.resource(name, { label?, icon? }) |
Opens the resource’s list. The resource leaves the sidebar. The label defaults to the view’s plural name. |
m.page(name, { label?, icon? }) |
Opens a composed page. The page leaves the sidebar. The label defaults to its title. |
m.link(label, href, { icon? }) |
Opens href in a new tab. Only https://, http:// and mailto: are accepted. |
accounts is the built-in Users page, which the config exports as usersPage from @protobase/layout; without the export, createAdmin refuses the item. Items keep their order. A line splits the menu into groups: these items, then the organization pages when the app has organizations, then the person’s own: “Account” for everyone (their account page: profile, passkeys and two-factor authentication) and “Sign-in policy” for admins (the sign-in policy, and the log of staff sign-ins); then the theme switch, and “Sign out” always comes last. icon is one of the names a view’s sidebar icon takes. A resource item without one uses the resource’s sidebar icon, and a link item uses external-link.
Every caller gets the menu through /meta, without the resources and pages they cannot see, so a user who cannot read organizations has no “Organization” item. Links are shown to everyone. createAdmin refuses to start when an item names a resource or page that does not exist, and configExports refuses a config that exports two menus.
protobase dev, protobase build and protobase serve pick the menu up from config/index.ts. With createAdmin directly, pass it as userMenu:
const { resources, views, userMenu } = configExports(config)const admin = createAdmin({ resources, views, userMenu, db, authenticate })