Examples
SvelteKit Example
Use SvelteKit forms and server loads with Kernia.
The SvelteKit example keeps auth state in Kernia cookies and forwards cookies to the Python backend from server loads.
Commands
pnpm create svelte@latest kernia-svelte
cd kernia-svelte
pnpm installEnvironment
AUTH_BASE_URL=http://localhost:8000/api/auth
PUBLIC_AUTH_BASE_URL=http://localhost:8000/api/authForm action
import { AUTH_BASE_URL } from "$env/static/private";
export const actions = {
default: async ({ request, fetch }) => {
const form = await request.formData();
const response = await fetch(`${AUTH_BASE_URL}/sign-in/email`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
email: form.get("email"),
password: form.get("password"),
remember_me: true,
}),
});
if (!response.ok) return { error: await response.json() };
return { ok: true };
},
};Server load
import { AUTH_BASE_URL } from "$env/static/private";
export async function load({ request, fetch }) {
const response = await fetch(`${AUTH_BASE_URL}/get-session`, {
headers: { cookie: request.headers.get("cookie") ?? "" },
});
return { session: response.ok ? await response.json() : null };
}Coverage
Test form sign-in, server load session reads, sign-out, OAuth return URLs, protected API calls, and cookie behavior in production mode.