Quick Start

Get kavach running in a SvelteKit project in minutes.

1. Run kavach init

From your SvelteKit project root. The wizard prompts for your adapter, providers, and route rules, then generates and patches all required files.

npx kavach init

Do not create kavach.config.js or modify vite.config.js / hooks.server.js manually — the CLI handles all of this correctly.

2. Fill in environment variables

kavach init adds the required variable names to .env with empty values. Fill them in from your backend dashboard.

# .env — fill in values from your backend project dashboard
PUBLIC_SUPABASE_URL=https://your-project.supabase.co
PUBLIC_SUPABASE_ANON_KEY=your-anon-key

3. Verify the setup

npx kavach doctor

All 7 checks should show ✓. If any show ✗, run kavach doctor --fix and follow the printed instructions.

4. Start your dev server

npm run dev

Navigate to your auth route (default /auth) to see the login page.

Advanced: manual setup (without CLI)

Only use this if the CLI cannot run in your environment. Manual setup is error-prone — run kavach doctor to verify afterwards.

1. Install packages

npm install kavach @kavach/vite @kavach/ui
npm install @kavach/adapter-supabase  # replace with your adapter

2. Create kavach.config.js

// kavach.config.js
export default {
  adapter: 'supabase',
  providers: [
    { name: 'google', label: 'Continue with Google' },
    { name: 'magic', mode: 'otp', label: 'Magic Link' }
  ],
  rules: [
    { path: '/auth', public: true },
    { path: '/', public: true },
    { path: '/dashboard', protected: true }
  ],
  env: {
    url: 'PUBLIC_SUPABASE_URL',
    anonKey: 'PUBLIC_SUPABASE_ANON_KEY'
  }
}

3. Patch vite.config.js

// vite.config.js — kavach() must come before sveltekit()
import { kavach } from '@kavach/vite'
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [kavach(), sveltekit()]
})

4. Add hooks.server.js

// src/hooks.server.js
import { kavach } from '$kavach/auth'
export const handle = kavach.handle

5. Add layout.server.js

// src/routes/+layout.server.js
export function load({ locals }) {
  return { session: locals.session }
}

Next Steps

Kavach — Authentication made simple llms.txt