feat: build the /admin and /admin/login pages

This commit is contained in:
wilson 2026-03-09 22:17:28 +00:00
parent 203e7c4b27
commit 1d24bde610
4 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,16 @@
import { redirect } from "@sveltejs/kit";
import type { LayoutServerLoad } from "./$types.js";
import { CookieAuthentication } from "$lib/blog/auth/CookieAuthentication.js";
export const load: LayoutServerLoad = ({ cookies, route }) => {
const auth = new CookieAuthentication(cookies)
const isAuthd = auth.isAuthdAsAdmin
if (route.id === '/admin/login' && isAuthd) {
return redirect(307, '/admin')
} else if (!isAuthd && route.id !== '/admin/login') {
return redirect(307, '/admin/login')
}
return {}
}

View file

@ -0,0 +1 @@
<h1>Welcome home, Wilson</h1>

View file

@ -0,0 +1,25 @@
import { PRIVATE_ADMIN_AUTH_TOKEN } from "$env/static/private";
import { redirect } from "@sveltejs/kit";
import type { Actions} from "./$types.js";
import { CookieAuthentication } from "$lib/blog/auth/CookieAuthentication.js";
export const actions = {
default: async ({cookies, request}) => {
const formData = await request.formData()
const token = formData.get('token')
const isAuthd = PRIVATE_ADMIN_AUTH_TOKEN === token;
const auth = new CookieAuthentication(cookies)
auth.setAdminAuthentication(isAuthd)
if (isAuthd) {
return redirect(307, '/admin')
}
return {
isAuthd
}
}
} satisfies Actions

View file

@ -0,0 +1,11 @@
<h1>Admin login</h1>
<form method="POST">
<div class="field">
<label for="token">API Token</label>
<input type="password" id="token" name="token" />
</div>
<div class="field">
<input type="submit" value="Login">
</div>
</form>