Vite Plugin

The Kavach Vite plugin reads kavach.config.js and generates the $kavach/auth virtual module at build time. Required for SvelteKit integration.

Installation

npm install @kavach/vite

Setup

Add to vite.config.js. The plugin must be listed before sveltekit():

import { kavach } from '@kavach/vite'
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    kavach(),     // must come before sveltekit()
    sveltekit()
  ]
})

Custom Config Path

By default the plugin looks for kavach.config.js in the project root. You can override this:

import { kavach } from '@kavach/vite'
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    kavach({ configPath: './config/kavach.config.js' }),
    sveltekit()
  ]
})

Options Reference

OptionTypeDescription
configPathstringPath to kavach.config.js. Defaults to <root>/kavach.config.js

What It Generates

The plugin generates the $kavach/auth virtual module which exports:

  • kavach — configured server-side instance with .handle hook
  • adapter — instantiated adapter (e.g. SupabaseAdapter)
  • logger — configured logger instance
// src/hooks.server.js
import { kavach } from '$kavach/auth'
export const handle = kavach.handle
// src/routes/+layout.svelte
const { adapter, logger } = await import('$kavach/auth')

Features

  • Virtual Module — Generates $kavach/auth from kavach.config.js
  • Hot Reload — Restarts the dev server when config changes
  • Multi-adapter — Supports supabase, firebase, auth0, amplify, convex

Next Steps

Kavach — Authentication made simple llms.txt