portico_auth_storage_sqlite 1.0.0
portico_auth_storage_sqlite: ^1.0.0 copied to clipboard
SQLite storage adapter for portico_auth_roles, portico_auth_credentials, and portico_auth_tokens.
Portico Auth Storage (SQLite) #
SQLite persistence layer for Portico Auth credentials, roles, and tokens. This package provides a robust storage solution using SQLite, ensuring your authentication data is persisted reliably across server restarts.
Features #
- Performant: Uses
sqflite_common_ffifor efficient and reliable database operations on desktop and server platforms. - Modular Adapters: Separate adapters for managing
AuthCredentialsManager,AuthRoles, andAuthTokensmetadata. - Automatic Schema Management: Handles table creation, indexes, and initialization automatically upon startup.
- Thread-Safe: Designed to handle concurrent access safely within a single process.
Getting started #
Add this package to your pubspec.yaml:
dependencies:
portico_auth_storage_sqlite: ^1.0.0
Interactive Web Simulator #
Experience the full capabilities of the Portico Auth ecosystem without setting up a backend. The Web Simulator runs the entire stack (Client, Server, and Storage) directly in your browser.
Usage #
1. Initialize Database #
Tip
You can use an in-memory database for testing or a file-based database for production.
import 'package:portico_auth_storage_sqlite/portico_auth_storage_sqlite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
void main() async {
// Initialize FFI for desktop/server
sqfliteFfiInit();
final db = await databaseFactoryFfi.openDatabase('auth_service.db');
// Initialize specific storage components
final tokenStorage = AuthTokensSqlite(db);
await tokenStorage.initialize();
final credentialStorage = AuthCredentialsSqlite(db);
await credentialStorage.initialize();
final roleStorage = AuthRolesSqlite(db);
await roleStorage.initialize();
}
2. Use with Portico Auth Managers #
Pass the storage adapters to your managers.
final credentials = AuthCredentialsManager(storage: credentialStorage);
final roleManager = AuthRoleManager(roleStorage);
final tokenManager = AuthTokensManager(
signingKey,
encryptingKey,
tokenStorage,
// ...
);
Examples #
- SQLite Storage Lifecycle Example: Demonstrates opening a database, initializing the schema, and performing basic CRUD operations for tokens.