| Crates.io | supabase-auth-redux |
| lib.rs | supabase-auth-redux |
| version | 0.1.0 |
| created_at | 2025-06-11 17:21:04.130733+00 |
| updated_at | 2025-06-11 17:21:04.130733+00 |
| description | Rust client library for Supabase Auth API |
| homepage | https://github.com/j7nw4r/supabase_auth_rs |
| repository | https://github.com/j7nw4r/supabase_auth_rs |
| max_upload_size | |
| id | 1708870 |
| size | 121,665 |
A Rust client library for the Supabase Auth API.
Add this to your Cargo.toml:
[dependencies]
supabase-auth-redux = "0.1.0"
use supabase_auth_redux::{AuthClient, AuthError, IdType};
#[tokio::main]
async fn main() -> Result<(), AuthError> {
// Initialize the client
let auth_client = AuthClient::new(
"https://your-project.supabase.co",
"your-anon-key"
)?;
// Sign up a new user
let (user, access_token) = auth_client
.signup(
IdType::Email("user@example.com".to_string()),
"secure_password".to_string(),
None,
)
.await?;
println!("User created: {}", user.id);
// Sign in an existing user
let token_response = auth_client
.signin_with_password(
IdType::Email("user@example.com".to_string()),
"secure_password".to_string(),
)
.await?;
println!("Access token: {}", token_response.access_token);
Ok(())
}
For more control over the client configuration, use the builder pattern:
use supabase_auth_rs::AuthClient;
let auth_client = AuthClient::builder()
.api_url("https://your-project.supabase.co")
.anon_key("your-anon-key")
.service_role_key("your-service-role-key") // Optional: for admin operations
.build()?;
// Get user by access token
let user = auth_client
.get_user_by_token(&access_token)
.await?;
// Refresh tokens
let new_tokens = auth_client
.refresh_token(&refresh_token)
.await?;
// Logout
auth_client
.logout(&access_token)
.await?;
Admin operations require a service role key:
let admin_client = AuthClient::builder()
.api_url("https://your-project.supabase.co")
.anon_key("your-anon-key")
.service_role_key("your-service-role-key")
.build()?;
// Hard delete a user (requires service role key)
admin_client
.hard_delete_user(user_id)
.await?;
// Soft delete a user (marks as deleted but keeps data)
admin_client
.soft_delete_user(user_id)
.await?;
signup() - Create a new user accountsignin_with_password() - Sign in with email/phone and passwordlogout() - Sign out a userrefresh_token() - Refresh access tokensget_user_by_token() - Validate a token and get user infoget_user_by_id() - Get user by UUID (requires service role key)hard_delete_user() - Permanently delete a user accountsoft_delete_user() - Mark user as deleted but keep dataThe library provides a comprehensive AuthError enum for different error scenarios:
use supabase_auth_rs::AuthError;
match auth_client.signin_with_password(id_type, password).await {
Ok(token_response) => {
println!("Signed in successfully!");
}
Err(AuthError::NotAuthorized) => {
println!("Invalid credentials");
}
Err(AuthError::InvalidParameters) => {
println!("Invalid input parameters");
}
Err(e) => {
println!("An error occurred: {}", e);
}
}
Tests require a local Supabase instance:
# Start local Supabase
supabase start
# Run tests
cargo test
# Run tests with service role key (for admin operations)
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key cargo test
Check out the examples directory for more detailed usage examples:
# Run the local Supabase example
cargo run --example local_supabase
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under either of
at your option.