Specials Part 14 of 14
  1. 1 The Invisible Models: Debugging 3D Rendering on iOS Physical Devices
  2. 2 Building 3D Scenes Through Conversation: An MCP Server for Geographic Objects
  3. 3 Rendering Conversational 3D Scenes with Three.js and MCP
  4. 4 Seven Dollars and Twenty-Five Years: Building an Expo Plugin with AI
  5. 5 The Force-Quit Crash: When Worklets Outlive Your App
  6. 6 The Conversational Consent Pattern: Privacy That Actually Respects Your Users
  7. 7 Streaming LLM Responses: A Partial JSON Parser for Structured Output
  8. 8 There Are No Emotions in Runtime Software
  9. 9 Streaming AI Responses from Server to Screen
  10. 10 The Danger of a Hidden Sun
  11. 11 A Partial JSON Parser You Can npm install
  12. 12 Everything I Automated on This Blog
  13. 13 I Moved This Blog to Umbraco for the Front Page
  14. 14 A Login Button Only Editors Can See
About this series

A Login Button Only Editors Can See

A Login Button Only Editors Can See

I read this blog on my own laptop more than anywhere else, because that is where it is written. Umbraco runs there, and the public site is exported from it as static files. When I spotted a mistake in a post on localhost, fixing it meant opening a new tab, going to /umbraco, logging in again if the session had run out, and finding the article in the content tree. I wanted a button on the page that goes straight to that page's editor, and that nobody else would ever see.

Nothing in the box does this

Umbraco has no such button. There are older community packages, uEditThis and Our.Umbraco.EditLink among them, that show an edit link while someone is logged in, and in Umbraco 14 and later a view can ask whether a backoffice user is signed in. Both answer whether you are logged in at this moment. The time I most want the button is after my session has expired, so the question I wanted asked was whether this browser has ever logged in.

How it decides

The package has two halves.

The first is a backoffice entry point, a few lines of JavaScript that Umbraco runs when the backoffice starts. The backoffice only starts after a successful login, so when this runs it sets a cookie on the site's domain:

document.cookie = `super_secret_login=1; Path=/; Max-Age=${60 * 60 * 24 * 400}; SameSite=Lax; Secure`;

It isn't Umbraco's session cookie, so logging out leaves it alone. Browsers won't keep a cookie for more than 400 days, so it is set again every time the backoffice opens.

The second half is a tag helper. Put this in the layout:

<super-secret-login-button />

and it renders the button only when that cookie comes with the request. Without the cookie the tag renders nothing: no hidden element, no script and no class name for anyone reading the source. On a content page the button links to that page in the backoffice editor.

The cookie is a hint and not a key. Anyone who sets it by hand gets a button that leads to the login screen every Umbraco site already has at /umbraco.

Why the public site never has it

stepinto.dev is static files, saved by a tool that asks the local site for every page. That tool sends no cookies, so every page it saves was rendered for a browser that has never logged in, and the button isn't in any of them. I added a check anyway: the export stops if the button's marker turns up in a page, so rendering it some other way by mistake fails the build instead of shipping a login button to readers.

So you won't find it by poking at this site. It only exists on my laptop. On an ordinary Umbraco site, where the backoffice and the pages share a domain, editors get it on the live site.

One warning for that case, which is in the README too. Anything that caches whole pages, such as output caching or a CDN, could store a copy with the button in it and hand it to everyone. Vary the cache on the cookie, or skip the cache for requests that carry it.

Trying it

The package is Umbraco.Community.SuperSecretLoginButton on NuGet, for Umbraco 17, with its source on GitHub under the MIT licence. It installs with:

dotnet add package Umbraco.Community.SuperSecretLoginButton

Add @addTagHelper *, Umbraco.Community.SuperSecretLoginButton to _ViewImports.cshtml, put the tag just before </body>, log in to the backoffice once and look at the site. The words on the button, the corner it sits in and where it links to can all be set on the tag.