Installation
Add rs-auth to your Rust project
Installation
This guide will walk you through adding rs-auth to your Rust project.
Prerequisites
Before installing rs-auth, ensure you have:
- Rust 1.70 or later
- PostgreSQL 14 or later
- Cargo installed
Add the Dependency
Add rs-auth to your Cargo.toml:
[dependencies]
rs-auth = "0.1"
axum = "0.7"
tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.8", features = ["postgres", "runtime-tokio-rustls"] }Required Dependencies
rs-auth requires several dependencies to function:
Web Framework
axum = "0.7"
tower = "0.5"
tower-http = { version = "0.6", features = ["cors"] }Database
sqlx = { version = "0.8", features = [
"postgres",
"runtime-tokio-rustls",
"migrate",
"chrono",
"uuid"
] }Async Runtime
tokio = { version = "1", features = ["full"] }Serialization
serde = { version = "1", features = ["derive"] }
serde_json = "1"Database Setup
rs-auth requires a PostgreSQL database. Create a new database:
createdb rs_auth_devSet your database URL as an environment variable:
export DATABASE_URL="postgresql://localhost/rs_auth_dev"Run Migrations
rs-auth includes a CLI tool for running database migrations:
cargo install --git https://github.com/rs-auth/rs-auth rs-auth-cliRun the migrations:
rs-auth-cli migrateThis will create the necessary tables:
users- User accountssessions- Active sessionsemail_verification_tokens- Email verification tokenspassword_reset_tokens- Password reset tokensoauth_accounts- OAuth provider accounts (if using OAuth)
Verify Installation
Create a simple test to verify rs-auth is installed correctly:
use rs_auth::AuthConfig;
#[tokio::main]
async fn main() {
let config = AuthConfig::default();
println!("rs-auth is installed! Config: {:?}", config);
}Run the test:
cargo runIf you see the config output, rs-auth is successfully installed!
Next Steps
Now that rs-auth is installed, you can:
- Follow the Quick Start guide to build your first authenticated endpoint
- Learn about Sessions and how rs-auth manages authentication state
- Explore the Configuration options