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.sveltesat at the$libroot andBack.svelte(a component) lived inlib/assets/;FileManager's test lived underroutes/while testing a$libcomponent, and its helper file sat incomponents/dash/;lib/index.tswas 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-autowas installed but unused, the README was the unmodifiedsvtemplate, and Vite ran withallowedHosts: true(no DNS-rebinding protection).
What changed #
$liblayout (allgit mv, imports updated):lib/AuthShell.svelte(+ test) →lib/components/auth/lib/assets/Back.svelte→lib/components/icons/components/dash/FileManager.svelteandFileManagerUtils.ts→components/dash/file-manager/{FileManager.svelte,utils.ts}; its test moved alongside it fromroutes/dash/- deleted the unused
lib/index.ts
- Logout is POST-only: new
routes/logout/+server.ts—GETjust redirects home,POSTclears the session cookie and redirects. Removedlogout/+page.svelte.AppHeaderrenders a<form method="POST" action="/logout">button;UserModPOSTs to/logoutafter a credentials change. Newroutes/logout/server.test.ts;AppHeader.test.tsupdated. - Tooling: removed
adapter-auto(and its template comments insvelte.config.js);allowedHostsis now.localhost,.localtest.me,.lvh.meand.$DOMAIN(a leading dot also allows subdomains, which user sites use);DOMAINis passed to the dev frontend container indocker-compose.dev.yml; rewrotefrontend/README.md.
Review notes #
- SvelteKit's built-in CSRF origin check applies to the logout form POST.
logoutdeletesaccess_tokenitself (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. IfAUTH_COOKIE_NAMEis ever changed, both sides need the new name (the hook already assumesaccess_token).- If you serve the dev frontend under a domain other than
localhost/localtest.me/lvh.me, setDOMAINin.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).