Make post-login redirect leave the SPA for proxied containers
Deploy with Docker Compose / deploy (push) Successful in 27s

nginx's admin auth_request gate bounces /notes/, /sb/ and /hasura/ to
/admin/login?redirect=<path>, but Login.vue completed that with
router.push(). Those paths are other containers, not Vue routes, so the
push matched the catch-all 404 route and the user never left the SPA.

Resolve the destination first: if it lands on the route named "404" there
is no Vue route for it, so use a real document request and let nginx
proxy it. Also reject non-site-relative destinations, since the value
comes straight from the query string.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-09-22 13:32:51 +01:00
co-authored by Claude Opus 5
parent afac428229
commit e5e43f3e0b
+30 -4
View File
@@ -1,7 +1,11 @@
<script setup>
/**
* Route `/admin/login`. On success redirects to `?redirect=` (set by the router
* guard when it bounced you here) or to /admin.
* Route `/admin/login`. On success redirects to `?redirect=` or to /admin.
*
* The `?redirect=` is set by two different gates: the SPA router guard
* (`meta.requiresAdmin`) and nginx's `auth_request` gate in front of the
* proxied containers (/notes/, /sb/, /hasura/). 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.
@@ -20,6 +24,29 @@ const password = ref("");
const submitting = ref(false);
const errorMsg = ref("");
// Send the browser to `dest`, choosing SPA navigation vs. a real page load.
//
// nginx bounces /notes/, /sb/ and /hasura/ here when the admin cookie 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 nginx 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.
function goTo(dest) {
if (typeof dest !== "string" || !dest.startsWith("/") || dest.startsWith("//")) {
router.push("/admin");
return;
}
if (router.resolve(dest).name !== "404") {
router.push(dest);
} else {
window.location.assign(dest);
}
}
async function handleLogin() {
if (submitting.value) return;
submitting.value = true;
@@ -29,8 +56,7 @@ async function handleLogin() {
// `loggedIn` rather than by catching.
await auth.logIn(username.value, password.value);
if (auth.loggedIn) {
const dest = route.query.redirect || "/admin";
router.push(dest);
goTo(route.query.redirect || "/admin");
} else {
errorMsg.value = "Invalid username or password";
}