Getting Started with Svelte Guardian
Welcome to the getting started section of the Svelte Guardian documentation. These guides will help you set up and configure Svelte Guardian in your SvelteKit project to implement comprehensive authentication and authorization functionality.
In This Section
- Installation - Install and configure Svelte Guardian
- Configuration - Configure Svelte Guardian options
- Authentication Pages - Create sign-in, sign-up, and other auth pages
- Route Protection - Protect routes based on authentication status
- Session Management - Manage user sessions
- User Profiles - Work with user data
- Directory Structure - Understand project organization
Prerequisites
- A SvelteKit project (v2.0.0 or higher)
- Node.js (v20 or higher)
- A database for storing user information (Prisma is recommended)
Installation
Basic Setup
1. Database Setup
Svelte Guardian works with various databases through adapters. Here’s an edamole with Prisma:
Add the required schema to your prisma/schema.prisma
file:
Run the migration:
2. Configure Svelte Guardian
Create a file at src/lib/server/auth.ts
:
Then create or modify your src/hooks.server.js
(or .ts
) file:
3. Create Sign-in and Sign-up Pages
Create basic sign-in and sign-up pages in your project. Here’s a simple example for src/routes/signin/+page.svelte
:
4. Configure Route Protection
To protect routes based on authentication status or user roles, add route protection to your configuration:
Getting Started Guides
Our getting started documentation is organized into the following sections:
- Introduction to Svelte Guardian - Overview of Svelte Guardian features and concepts
- Installation - Step-by-step installation instructions
- Configuration - Detailed configuration options
- Authentication Pages - Creating sign-in, sign-up, and other authentication pages
- Route Protection - Protecting routes based on authentication status and user roles
- Session Management - Working with user sessions
- User Data and Profiles - Managing user data and profiles
Next Steps
After completing the getting started guides, you might want to explore these additional features:
- Email Verification and Password Reset
- OAuth Providers
- Two-Factor Authentication
- Advanced Security Features
- Implementing Two-Factor Authentication
- Customizing Email Templates
- Rate Limiting and Security Features
For a complete list of configuration options, check the Configuration Reference.