supabase_auth/
lib.rs

1#![cfg(not(doctest))]
2#![forbid(unsafe_code)]
3#![deny(missing_debug_implementations)]
4
5/*!
6# Supabase Auth
7
8[![Crates.io License](https://img.shields.io/crates/l/supabase-auth?style=for-the-badge)](https://crates.io/crates/supabase-auth)
9[![Crates.io Version](https://img.shields.io/crates/v/supabase-auth?style=for-the-badge)](https://crates.io/crates/supabase-auth)
10[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/proziam/supabase-auth-rs/rust.yml?branch=main&style=for-the-badge)](https://github.com/proziam/supabase-auth-rs)
11[![docs.rs](https://img.shields.io/docsrs/supabase-auth?style=for-the-badge)](https://docs.rs/supabase-auth/latest/supabase_auth/index.html)
12
13A Rust implementation of the [supabase js auth client](https://github.com/supabase/gotrue-js).
14The goal is to have feature parity and an easy-to-use API.
15
16Currently this software is functional, but not yet battle-tested. The goal is to go to 1.0.0
17by the end of December, 2024.
18
19## Installation
20
21Add this to your `Cargo.toml`:
22
23```toml
24[dependencies]
25supabase-auth = "0.1.0"
26```
27
28Or use cargo-add:
29
30```bash
31cargo add supabase-auth
32```
33
34## Usage
35
36### Create an Auth Client
37
38```rust
39// You can manually pass in the values
40let auth_client = AuthClient::new(project_url, api_key, jwt_secret).unwrap();
41
42// Or you can use environment variables
43// Requires `SUPABASE_URL`, `SUPABASE_API_KEY`, and `SUPABASE_JWT_SECRET` environment variables
44let auth_client = AuthClient::new_from_env().unwrap();
45```
46
47### Sign Up
48
49```rust
50// Sign up methods return the session which you can use for creating cookies
51let session = auth_client
52    .sign_up_with_email_and_password(demo_email, demo_password)
53    .await
54    .unwrap();
55
56// You can also sign up using a phone number and password
57let session = auth_client
58    .sign_up_with_phone_and_password(demo_phone, demo_password)
59    .await
60    .unwrap();
61```
62
63### Sign In
64
65```rust
66// Sign in methods return the session which you can use for creating cookies
67let session = auth_client
68    .login_with_email(&demo_email, &demo_password)
69    .await
70    .unwrap();
71
72// You can also login using a phone number
73let session = auth_client
74    .login_with_phone(demo_phone, demo_password)
75    .await
76    .unwrap();
77```
78
79### OAuth
80
81```rust
82// Returns the provider and the url where the user will continue the auth flow
83let oauth_response = auth_client
84    .login_with_oauth(Provider::Github, None)
85    .await
86    .unwrap();
87
88// You can also customize the options like so:
89let mut query_params = HashMap::new();
90query_params.insert("key".to_string(), "value".to_string());
91query_params.insert("second_key".to_string(), "second_value".to_string());
92query_params.insert("third_key".to_string(), "third_value".to_string());
93
94let options = SignInWithOAuthOptions {
95    query_params: Some(query_params),
96    redirect_to: Some("your-redirect-url".to_string()),
97    scopes: Some("repo gist notifications".to_string()),
98    skip_brower_redirect: Some(true),
99};
100
101let response = auth_client
102    .login_with_oauth(Provider::Github, Some(options))
103    .await
104    .unwrap();
105```
106
107### SSO
108
109NOTE: Requires an SSO Provider and Supabase Pro plan
110
111```rust
112let params = SignInWithSSO {
113    domain: Some(demo_domain),
114    options: None,
115    provider_id: None,
116};
117
118// Returns the URL where the user will continue the auth flow with your SSO provider
119let url = auth_client.sso(params).await.unwrap();
120```
121
122## Features
123
124* ✓ Create Client
125* ✓ Sign In with Email & Password
126* ✓ Sign In with Phone & Password
127* ✓ Sign Up with Email & Password
128* ✓ Sign Up with Phone & Password
129* ✓ Sign In with Third Party Auth (OAuth)
130* ✓ Sign In with Magic Link
131* ✓ Send Sign-In OTP (Email, SMS, Whatsapp)
132* ✓ Sign In with OTP
133* ✓ Refresh Session
134* ✓ Resend OTP Tokens (Email & SMS)
135* ✓ Retrieve User
136* ✓ Reset Password
137* ✓ Change User Data (e.g., Email or password)
138* ✓ SSO
139*/
140
141pub mod client;
142pub mod error;
143pub mod models;