From 7ddf8aa3d88b91d065186eab9e8093d0d2f71a3a Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sun, 29 Sep 2024 22:16:49 +1000 Subject: [PATCH] QOL: make login page redirect to previous page on success --- src/components/navbar/Navbar.svelte | 36 ++++++++------ src/routes/admin/+page.svelte | 2 + src/routes/admin/LogOutAll.svelte | 15 ++++++ src/routes/admin/login/+page.server.ts | 3 +- src/routes/admin/login/+page.svelte | 65 ++++++++++++++++++-------- 5 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 src/routes/admin/LogOutAll.svelte diff --git a/src/components/navbar/Navbar.svelte b/src/components/navbar/Navbar.svelte index 3ff6c13d..efe77aad 100644 --- a/src/components/navbar/Navbar.svelte +++ b/src/components/navbar/Navbar.svelte @@ -1,11 +1,11 @@ @@ -38,7 +48,7 @@ {config.siteShortName} / {#each path.slice(0, -1) as p, i} {p.txt} - {'/ '} + {"/ "} {/each} {path[path.length - 1].txt} @@ -48,14 +58,14 @@ {#if loggedIn} - + {:else if loggedIn !== undefined} - + {/if} - + {#if dev} diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index d9a7741c..75e2d9d9 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -6,6 +6,7 @@ import GitSettings from "./GitSettings.svelte"; import ChangePassword from "./ChangePassword.svelte"; import ReloadData from "./ReloadData.svelte"; + import LogOutAll from "./LogOutAll.svelte"; export let data: import("./$types").PageData; @@ -32,6 +33,7 @@
+
diff --git a/src/routes/admin/LogOutAll.svelte b/src/routes/admin/LogOutAll.svelte new file mode 100644 index 00000000..d099f452 --- /dev/null +++ b/src/routes/admin/LogOutAll.svelte @@ -0,0 +1,15 @@ + + +
+

Log out of all sessions

+

This will sign you out on all of your devices (including this one).

+ +
diff --git a/src/routes/admin/login/+page.server.ts b/src/routes/admin/login/+page.server.ts index 92f2dd1e..a28b8f4b 100644 --- a/src/routes/admin/login/+page.server.ts +++ b/src/routes/admin/login/+page.server.ts @@ -12,7 +12,8 @@ export async function load(req) { loggedIn = true; } catch { /* empty */ } if (loggedIn) { - redirect(303, '/admin'); + // If they are logged in, redirect them to the `from` URL if it exists. + redirect(303, req.url.searchParams.get("from") || '/'); } const globals = await getPortfolioGlobals(); return { globals }; diff --git a/src/routes/admin/login/+page.svelte b/src/routes/admin/login/+page.svelte index 87124ebb..1a49adc4 100644 --- a/src/routes/admin/login/+page.svelte +++ b/src/routes/admin/login/+page.svelte @@ -1,29 +1,41 @@ login - {data.globals.config.siteName} - - + + - + @@ -32,8 +44,8 @@ config={data.globals.config} loggedIn={false} path={[ - { txt: 'Admin', url: 'admin' }, - { txt: 'Login', url: 'login' }, + { txt: "Admin", url: "admin" }, + { txt: "Login", url: "login" }, ]} /> @@ -41,17 +53,32 @@
-

Login

+

Login

Username

- +

Password

- +

- +