Arcjet SDK for SvelteKit
npm install @arcjet/sveltekit@arcjet/sveltekit[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.
This is the [Arcjet][arcjet] SDK for [SvelteKit][sveltekit].
- npm package (@arcjet/sveltekit)
- GitHub source code (arcjet-sveltekit/ in arcjet/arcjet-js)
Visit the [quick start guide][quick-start] to get started.
Try an Arcjet protected Next.js app live at
[example.arcjet.com][example-next-url]
([source code][example-next-source]).
See [arcjet/example-sveltekit][example-sveltekit-source] for a SvelteKit
example.
This is our adapter to integrate Arcjet into SvelteKit.
Arcjet helps you secure your SvelteKit web application.
This package exists so that we can provide the best possible experience to
SvelteKit users.
You can use this if you are using SvelteKit.
See our [_Get started_ guide][arcjet-get-started] for other supported
frameworks.
This package is ESM only.
Install with npm in Node.js:
``sh`
npm install @arcjet/sveltekit
Configure Arcjet in hooks.server.ts:
`ts
import { env } from "$env/dynamic/private";
import arcjet, { shield } from "@arcjet/sveltekit";
import { type RequestEvent, error } from "@sveltejs/kit";
// Get your Arcjet key at
// Set it as an environment variable instead of hard coding it.
const arcjetKey = env.ARCJET_KEY;
if (!arcjetKey) {
throw new Error("Cannot find ARCJET_KEY environment variable");
}
const aj = arcjet({
key: arcjetKey,
rules: [
// Shield protects your app from common attacks.
// Use DRY_RUN instead of LIVE to only log.
shield({ mode: "LIVE" }),
],
});
export async function handle({
event,
resolve,
}: {
event: RequestEvent;
resolve(event: RequestEvent): Response | Promise
}): Promise
const decision = await aj.protect(event);
if (decision.isDenied()) {
return error(403, "Forbidden");
}
// Continue with the route
return resolve(event);
}
``
For more on how to configure Arcjet with SvelteKit and how to protect
SvelteKit,
see the [Arcjet SvelteKit SDK reference][arcjet-reference-sveltekit] on our
website.
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
[arcjet-get-started]: https://docs.arcjet.com/get-started
[arcjet-reference-sveltekit]: https://docs.arcjet.com/reference/sveltekit
[arcjet]: https://arcjet.com
[example-next-source]: https://github.com/arcjet/example-nextjs
[example-next-url]: https://example.arcjet.com
[example-sveltekit-source]: https://github.com/arcjet/example-sveltekit
[sveltekit]: https://kit.svelte.dev/
[quick-start]: https://docs.arcjet.com/get-started/sveltekit
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0