🦀 Supabase-rust
supabase-rust is a light Rust wrapper around the Supabase REST API.
Features
- Client creation with validation
- Unified error type (
supabase_rust::Error) - Sign-in email/pass (returns typed
AuthResponse) - Signup email/pass
- Signup phone/pass
- Token refresh
- Logout
- Verify one-time token
- Authorize external OAuth provider
- Password recovery
- Resend one-time password over email or SMS
- Magic link authentication
- One-time password authentication
- Retrieval of user's information
- Reauthentication of a password change
- Enrollment of MFA
- MFA challenge and verify
- OAuth callback
- All SSO
- All Admin
- Database support (CRUD operations with fluent query builder)
Quickstart
Add the following dependency to your Cargo.toml:
[]
= "0.3"
= { = "1", = ["full"] }
= { = "1.0", = ["derive"] }
Client Initialization
You can initialize the client with explicit values or via environment variables.
Supabase::new() returns a Result and will return an error if the URL or API
key is missing.
use Supabase;
// Option 1: Using environment variables
// Set SUPABASE_URL, SUPABASE_API_KEY, and optionally SUPABASE_JWT_SECRET
let client = new?;
// Option 2: Explicit configuration
let client = new?;
Usage
Authentication
Auth methods return typed responses: AuthResponse (with access_token,
refresh_token, etc.) or EmptyResponse (with status). Non-2xx responses
are automatically converted to Error::Api.
use ;
async
Database Operations
The library provides a fluent query builder for PostgREST database operations.
The QueryBuilder is annotated with #[must_use] so the compiler will warn if
you forget to call .execute().
use ;
use ;
async
Available Filter Methods
| Method | Description | PostgREST Equivalent |
|---|---|---|
eq(col, val) |
Equal | col=eq.val |
neq(col, val) |
Not equal | col=neq.val |
gt(col, val) |
Greater than | col=gt.val |
gte(col, val) |
Greater than or equal | col=gte.val |
lt(col, val) |
Less than | col=lt.val |
lte(col, val) |
Less than or equal | col=lte.val |
like(col, pattern) |
Pattern match (use * as wildcard) |
col=like.pattern |
ilike(col, pattern) |
Case-insensitive pattern match | col=ilike.pattern |
in_(col, &[vals]) |
Value in list | col=in.(v1,v2,v3) |
is_null(col) |
Is null | col=is.null |
not_null(col) |
Is not null | col=not.is.null |
Query Modifiers
| Method | Description |
|---|---|
order(col) |
Order by column (use col.desc for descending) |
limit(n) |
Limit number of rows |
offset(n) |
Skip first n rows |
Combining Filters
Filters can be chained to create complex queries:
let response = client
.from
.select
.gte
.lte
.neq
.in_
.order
.limit
.execute
.await?;
Error Handling
All operations return Result<T, supabase_rust::Error>. The error type has the
following variants:
| Variant | Description |
|---|---|
Error::Config(String) |
Missing URL or API key at construction |
Error::Request(reqwest::Error) |
HTTP transport failure |
Error::Serialization(serde_json::Error) |
JSON serialization/deserialization failure |
Error::Jwt(jsonwebtoken::errors::Error) |
JWT validation failure |
Error::AuthRequired(String) |
Operation requires a bearer token |
Error::Api { status, message } |
Non-2xx HTTP response from Supabase |
Tips
The Supabase team has an outline of their OpenAPI specs over in this yaml file.
License
Supabase-rust is available under the MIT license, see the LICENSE file for more information.