supabase-auth-redux
A Rust client library for the Supabase Auth API.
Features
- 🔐 Full authentication flow support (signup, signin, logout)
- 🔄 Token management (refresh, validation)
- 👤 User management (get user, update, delete)
- 🛡️ Admin operations with service role key
- 🚀 Async/await support with Tokio
- 📝 Comprehensive error handling
- 🎯 Type-safe API
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
use ;
async
Advanced Usage
Using the Builder Pattern
For more control over the client configuration, use the builder pattern:
use AuthClient;
let auth_client = builder
.api_url
.anon_key
.service_role_key // Optional: for admin operations
.build?;
User Management
// Get user by access token
let user = auth_client
.get_user_by_token
.await?;
// Refresh tokens
let new_tokens = auth_client
.refresh_token
.await?;
// Logout
auth_client
.logout
.await?;
Admin Operations
Admin operations require a service role key:
let admin_client = builder
.api_url
.anon_key
.service_role_key
.build?;
// Hard delete a user (requires service role key)
admin_client
.hard_delete_user
.await?;
// Soft delete a user (marks as deleted but keeps data)
admin_client
.soft_delete_user
.await?;
API Reference
Authentication Methods
signup()
- Create a new user accountsignin_with_password()
- Sign in with email/phone and passwordlogout()
- Sign out a user
Token Management
refresh_token()
- Refresh access tokensget_user_by_token()
- Validate a token and get user info
User Management
get_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 data
Error Handling
The library provides a comprehensive AuthError
enum for different error scenarios:
use AuthError;
match auth_client.signin_with_password.await
Requirements
- Rust 1.70 or later
- Tokio runtime
Development
Running Tests
Tests require a local Supabase instance:
# Start local Supabase
# Run tests
# Run tests with service role key (for admin operations)
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
Examples
Check out the examples directory for more detailed usage examples:
# Run the local Supabase example
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
- Built for use with Supabase
- Inspired by the official Supabase JavaScript client