clove/allInOne
web/src/routes/user/login/+page.svelte
back to web/src/routes/user/login
<!-- src/routes/user/login/+page.svelte
Copyright (c) 2026 Clove Nytrix Doughmination Twilight
Licensed under the DASL-1.0 Licence.
See LICENCE.md in the project root for full licence information.
-->
<script lang="ts">
import IcKey from "~icons/ic/outline-key";
import { goto } from "$app/navigation";
import { page } from "$app/state";
import { client } from "#lib/api.ts";
import { auth } from "#lib/auth.svelte.ts";
let username = $state("");
let password = $state("");
let pending = $state(false);
let error = $state("");
async function signIn(event: SubmitEvent) {
event.preventDefault();
if (pending) return;
pending = true;
error = "";
try {
auth.signIn(await client.localSignIn(username, password));
password = "";
const from = page.url.searchParams.get("from") || "/";
const target = /^\/(?![\/\\])/.test(from) ? from : "/";
await goto(target === "/admin/login" ? "/admin/dash" : target, {
replaceState: true,
});
} catch (failure) {
error = failure instanceof Error ? failure.message : "Sign-in failed.";
} finally {
pending = false;
}
}
</script>
<svelte:head>
<title>Sign in · Plural System</title>
<meta name="robots" content="noindex" />
</svelte:head>
<div class="page narrow">
<section class="panel">
<h1>Sign in</h1>
{#if error}
<p class="notice error" role="alert">{error}</p>
{/if}
<form onsubmit={signIn}>
<label>
Username
<input required autocomplete="username" bind:value={username} />
</label>
<label>
Password
<input required type="password" autocomplete="current-password" bind:value={password} />
</label>
<button class="primary" disabled={pending}>
<IcKey width="18" height="18" />
{pending ? "Signing in…" : "Sign in"}
</button>
</form>
</section>
</div>
<style>
form,
label {
display: grid;
gap: 0.5rem;
}
form {
gap: 1rem;
justify-items: start;
}
</style>