Trim comments to the non-obvious why
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s

Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 20:49:03 +00:00
co-authored by Claude Opus 5.5
parent effddd2794
commit 4530cb8dc4
222 changed files with 1173 additions and 5423 deletions
+7 -29
View File
@@ -1,17 +1,8 @@
<script setup>
/**
* Route `/admin/login`, the one login page for everyone: admins and accounts
* granted a gated service (the receipt printer, say). On success redirects to
* `?redirect=`, or else to /admin for an admin and /account for anyone else
* (a non-admin would only bounce off /admin's guard back to here).
*
* The `?redirect=` is set by two different gates: the SPA router guard
* (`meta.requiresAdmin`) and Caddy's `forward_auth` gate in front of the
* proxied containers (/notes/, /sb/, /receipt/). The latter means the
* destination is frequently NOT a Vue route, so see goTo() below.
*
* auth.logIn() never throws — it swallows the error — so success is detected by
* re-reading `auth.loggedIn` afterwards rather than by a try/catch.
* Route `/admin/login` for every account. Redirects to `?redirect=`, else
* /admin or /account. Caddy's gates also set `?redirect=`, often to a non-Vue
* path (see goTo).
*/
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";
@@ -20,10 +11,7 @@ import { useAuthStore } from "@/stores/auth";
import Button from "@/components/input/Button.vue";
const auth = useAuthStore();
// Nothing else on this route resolves the session: the guard only runs for
// admin routes and the home query is not issued here. Without this, someone
// already signed in who opens /admin/login directly would see the login form
// instead of the "Already signed in" card.
// Nothing else here resolves the session, so a signed-in visitor would see the form.
auth.ensureLoaded();
const router = useRouter();
const route = useRoute();
@@ -32,17 +20,8 @@ const password = ref("");
const submitting = ref(false);
const errorMsg = ref("");
// Send the browser to `dest`, choosing SPA navigation vs. a real page load.
//
// Caddy bounces /notes/, /sb/, /receipt/ and the like here when the session
// is missing; those paths belong to other containers, so router.push() would just
// match the catch-all 404 route and never leave the SPA. Resolving the path
// first tells us which it is: the catch-all matches everything, so landing on
// the route named "404" means no real Vue route exists and the browser needs a
// full document request for Caddy to proxy it.
//
// `dest` comes from the query string, so it is only followed when it is a
// site-relative path — a leading "//" or a scheme would be an open redirect.
// Caddy-gated paths aren't Vue routes, so landing on "404" means a full page
// load. Only site-relative paths are followed, or it's an open redirect.
function goTo(dest) {
if (typeof dest !== "string" || !dest.startsWith("/") || dest.startsWith("//")) {
router.push(home());
@@ -65,8 +44,7 @@ async function handleLogin() {
submitting.value = true;
errorMsg.value = "";
try {
// logIn() swallows its error, so success is detected by re-reading
// `loggedIn` rather than by catching.
// logIn() swallows errors, so re-read `loggedIn`.
await auth.logIn(username.value, password.value);
if (auth.loggedIn) {
goTo(route.query.redirect || home());