Skip to content

Integrating with SvelteKit

Terminal window
npm install @authaction/server-sdk
src/lib/auth.server.ts
import { createSvelteAuth } from "@authaction/server-sdk/svelte";
import { env } from "$env/dynamic/private";
export const auth = createSvelteAuth({
domain: env.AUTHACTION_DOMAIN,
clientId: env.AUTHACTION_CLIENT_ID,
redirectUri: env.AUTHACTION_REDIRECT_URI,
sessionSecret: env.SESSION_SECRET,
});
src/routes/auth/login/+server.ts
import { auth } from "$lib/auth.server";
export const GET = (event) => auth.handleLogin(event);
// src/hooks.server.ts — populates event.locals.session on every request
export const handle = auth.handle;
// src/routes/dashboard/+page.server.ts
export async function load({ locals }) {
if (!locals.session) throw redirect(302, "/auth/login");
return { user: locals.session.user };
}

Full SDK reference: github.com/authaction/authaction-server-sdk