| Crates.io | torii-storage-sqlite |
| lib.rs | torii-storage-sqlite |
| version | 0.5.1 |
| created_at | 2025-02-27 04:19:53.31847+00 |
| updated_at | 2025-07-23 00:21:07.485565+00 |
| description | SQLite storage backend for the torii authentication ecosystem |
| homepage | |
| repository | https://github.com/cmackenzie1/torii-rs |
| max_upload_size | |
| id | 1571236 |
| size | 144,318 |
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.
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 metadataAll 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