JSPM

  • Created
  • Published
  • Downloads 1097
  • Score
    100M100P100Q112326F
  • License Apache-2.0

Arcjet SDK for SvelteKit

Package Exports

  • @arcjet/sveltekit
  • @arcjet/sveltekit/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@arcjet/sveltekit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Arcjet Logo

@arcjet/sveltekit

npm badge

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 SDK for SvelteKit.

Getting started

Visit the quick start guide to get started.

Example app

Try an Arcjet protected app live at https://example.arcjet.com (source code).

What is this?

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.

When should I use this?

You can use this if you are using SvelteKit. See our Get started guide for other supported frameworks.

Install

This package is ESM only. Install with npm in Node.js:

npm install @arcjet/sveltekit

Use

Configure Arcjet in hooks.server.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 <https://app.arcjet.com>.
// 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<Response>;
}): Promise<Response> {
  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 on our website.

License

Apache License, Version 2.0 © Arcjet Labs, Inc.