A lightweight, self-hosted multi-tenant web publishing platform

refactor(frontend): tidy $lib layout, POST-only logout, tighten dev config #12

Merged pre1ude.dev
targeting dev from refactor/frontend-structure
Merged opened by pre1ude.dev
targeting dev from refactor/frontend-structure

refactor(frontend): tidy $lib layout, POST-only logout, tighter dev config #

Why #

The audit flagged a few SvelteKit and $lib convention problems that are cheap to fix on their own:

  • AuthShell.svelte sat at the $lib root and Back.svelte (a component) lived in lib/assets/;
  • FileManager's test lived under routes/ while testing a $lib component, and its helper file sat in components/dash/;
  • lib/index.ts was a barrel nothing imported;
  • logout was a GET page that logged the user out on load, so any other site could log users out by linking to it (and the app sets data-sveltekit-preload-data="hover");
  • @sveltejs/adapter-auto was installed but unused, the README was the unmodified sv template, and Vite ran with allowedHosts: true (no DNS-rebinding protection).

What changed #

  • $lib layout (all git mv, imports updated):
    • lib/AuthShell.svelte (+ test) → lib/components/auth/
    • lib/assets/Back.svelte → lib/components/icons/
    • components/dash/FileManager.svelte and FileManagerUtils.ts → components/dash/file-manager/{FileManager.svelte,utils.ts}; its test moved alongside it from routes/dash/
    • deleted the unused lib/index.ts
  • Logout is POST-only: new routes/logout/+server.ts — GET just redirects home, POST clears the session cookie and redirects. Removed logout/+page.svelte. AppHeader renders a <form method="POST" action="/logout"> button; UserMod POSTs to /logout after a credentials change. New routes/logout/server.test.ts; AppHeader.test.ts updated.
  • Tooling: removed adapter-auto (and its template comments in svelte.config.js); allowedHosts is now .localhost, .localtest.me, .lvh.me and .$DOMAIN (a leading dot also allows subdomains, which user sites use); DOMAIN is passed to the dev frontend container in docker-compose.dev.yml; rewrote frontend/README.md.

Review notes #

  • SvelteKit's built-in CSRF origin check applies to the logout form POST.
  • logout deletes access_token itself (the cookie is host-only, path /, same as the backend sets). It does not call the backend, since the backend logout only clears the cookie. If AUTH_COOKIE_NAME is ever changed, both sides need the new name (the hook already assumes access_token).
  • If you serve the dev frontend under a domain other than localhost/localtest.me/lvh.me, set DOMAIN in .env, otherwise Vite will reject the Host header.

Not in this PR #

Moving data fetching from onMount into +page.ts / +layout.server.ts loads, (app)/(auth) route groups, form actions for the auth pages, and a jsdom/browser test setup for interaction tests. Currently an expired session shows an error after client-side navigation instead of redirecting to login; fixing that properly needs an invalidation design that should be checked in a browser.

Testing #

  • bun run test (127 passing), bun run check (0 errors), bun run build — all clean.
  • Not tested manually in a browser: header logout button, and the post-credential-change logout in UserMod.

Merge notes #

Independent of refactor/backend-structure; the two touch different directories and should merge in either order. Changes package.json / bun.lock (removal of adapter-auto only).

Commits 1

refactor(frontend): tidy $lib layout, POST-only logout, tighten dev config
Sign up or Sign in to add to the discussion.