SQLite storage backend for the Torii authentication framework.
This crate provides a complete SQLite-based storage implementation for Torii, including all core authentication features like user management, sessions, passwords, OAuth, passkeys, and magic links.
- User Management: Store and retrieve user accounts with email verification support
- Session Management: Handle user sessions with configurable expiration
- Password Authentication: Secure password hashing and verification
- OAuth Integration: Store OAuth account connections and tokens
- Passkey Support: WebAuthn/FIDO2 passkey storage and challenge management
- Magic Link Authentication: Generate and verify magic links for passwordless login
- Database Migrations: Automatic schema management and upgrades
Add this to your Cargo.toml:
[dependencies]
torii-storage-sqlite = "0.4.0"use torii_storage_sqlite::SqliteStorage;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to SQLite database
let storage = SqliteStorage::connect("sqlite://todos.db?mode=rwc").await?;
// Run migrations to set up the schema
storage.migrate().await?;
// Use with Torii
let repositories = Arc::new(storage.into_repository_provider());
let torii = torii::Torii::new(repositories);
Ok(())
}use torii_storage_sqlite::SqliteStorage;
use torii::{Torii, SessionConfig};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let storage = SqliteStorage::connect("sqlite://auth.db?mode=rwc").await?;
storage.migrate().await?;
let repositories = Arc::new(storage.into_repository_provider());
let torii = Torii::new(repositories);
// Register a user
let user = torii.register_user_with_password("user@example.com", "secure_password").await?;
// Login
let (user, session) = torii.login_user_with_password(
"user@example.com",
"secure_password",
None, // user_agent
None, // ip_address
).await?;
println!("User logged in: {}", user.email);
println!("Session token: {}", session.token);
Ok(())
}The SQLite schema includes the following tables:
users- User accounts and profile informationsessions- Active user sessionspasswords- Hashed password credentialsoauth_accounts- Connected OAuth accountspasskeys- WebAuthn passkey credentialspasskey_challenges- Temporary passkey challengesmagic_links- Magic link tokens and metadata
All tables include appropriate indexes for optimal query performance.
This crate provides SqliteRepositoryProvider which implements the RepositoryProvider trait from torii-core, allowing it to be used directly with the main Torii authentication coordinator.
This crate implements the following storage traits:
UserStorage- User account managementSessionStorage- Session management- Password repository for secure password storage
- OAuth repository for third-party authentication
- Passkey repository for WebAuthn support
- Magic link repository for passwordless authentication