Overview
Add your Invent AI assistant to any SvelteKit application. Perfect for Svelte applications with server-side rendering and static generation.Installation
1
Create Assistant Component
2
Configure Environment
Add to
.env:User Authentication
Server-Side Hash Generation
Use SvelteKit server endpoints:Using Server Load Functions
Integration with Lucia Auth
TypeScript Support
Add type declarations:Using Stores
Create a store for user authentication:Tips for SvelteKit
Server Load Functions
Use server load for secure hash generation
Type Safety
Full TypeScript support with proper types
SSR Compatible
Works with SSR and SPA modes
Reactive
Leverage Svelte’s reactivity system
Troubleshooting
Script not loading
Script not loading
Solutions:
- Check browser guard:
if (browser) - Ensure script loads in onMount
- Verify URL is correct
- Check browser console for errors
SSR hydration issues
SSR hydration issues
Solutions:
- Use browser check before accessing window
- Load script client-side only
- Ensure user data is fetched client-side if needed
Environment variables not working
Environment variables not working
Solutions:
- Restart dev server after adding env variables
- Use
PUBLIC_prefix for public variables - Keep secret key without prefix (private)
- Check import from correct $env module
Best Practices
- Use server load functions or endpoints for hash generation
- Keep secret key in
.env(never commit) - Use
PUBLIC_prefix only for non-sensitive variables - Always check
browserbefore accessing window - Leverage SvelteKit’s built-in security features