#supabase #api-client #third-party

supabase-auth

Supabase Auth implementation following the official client libraries

13 releases

new 0.10.3 Nov 16, 2024
0.9.2 Oct 23, 2024
0.1.8 Sep 18, 2024

#179 in Authentication

Download history 283/week @ 2024-09-08 511/week @ 2024-09-15 46/week @ 2024-09-22 100/week @ 2024-09-29 350/week @ 2024-10-13 147/week @ 2024-10-20 33/week @ 2024-10-27 2/week @ 2024-11-03 58/week @ 2024-11-10

253 downloads per month
Used in suparust

MIT/Apache

60KB
1K SLoC

Supabase Auth

This is a Rust implementation of the supabase js auth client. The goal is to have feature parity and an easy-to-use API.

Currently this software is functional, but not yet battle-tested. The goal is to go to 1.0.0 by the end of December, 2024.

Installation

Cargo

cargo add supabase-auth 

Usage

Create an Auth Client

// You can manually pass in the values
let auth_client = AuthClient::new(project_url, api_key, jwt_secret).unwrap();

// Or you can use environment variables
// Requires `SUPABASE_URL`, `SUPABASE_API_KEY`, and `SUPABASE_JWT_SECRET` environment variables
let auth_client = AuthClient::new_from_env().unwrap();

Sign Up

// Sign up methods return the session which you can use for creating cookies
let session = auth_client
    .sign_up_with_email_and_password(demo_email, demo_password)
    .await
    .unwrap();

// You can also sign up using a phone number and password
let session = auth_client
    .sign_up_with_phone_and_password(demo_phone, demo_password)
    .await
    .unwrap();

Sign In

// Sign in methods return the session which you can use for creating cookies
let session = auth_client
    .login_with_email(&demo_email, &demo_password)
    .await
    .unwrap();

// You can also login using a phone number
let session = auth_client
    .login_with_phone(demo_phone, demo_password)
    .await
    .unwrap();

OAuth

// Returns the provider and the url where the user will continue the auth flow
let oauth_response = auth_client
    .login_with_oauth(Provider::Github, None)
    .await
    .unwrap();

// You can also customize the options like so:
let mut query_params = HashMap::new();

query_params.insert("key".to_string(), "value".to_string());
query_params.insert("second_key".to_string(), "second_value".to_string());
query_params.insert("third_key".to_string(), "third_value".to_string());

let options = SignInWithOAuthOptions {
    query_params: Some(query_params),
    redirect_to: Some("your-redirect-url".to_string()),
    scopes: Some("repo gist notifications".to_string()),
    skip_brower_redirect: Some(true),
};

let response = auth_client
    .login_with_oauth(Provider::Github, Some(options))
    .await
    .unwrap();

SSO

NOTE: Requires an SSO Provider and Supabase Pro plan

let params = SignInWithSSO {
    domain: Some(demo_domain),
    options: None,
    provider_id: None,
};

// Returns the URL where the user will continue the auth flow with your SSO provider
let url = auth_client.sso(params).await.unwrap();

Features

  • Create Client
  • Sign In with Email & Password
  • Sign In with Phone & Password
  • Sign Up with Email & Password
  • Sign Up with Phone & Password
  • Sign In with Third Party Auth (OAuth)
  • Sign In with Magic Link
  • Send Sign-In OTP (Email, SMS, Whatsapp)
  • Sign In with OTP
  • Refresh Session
  • Resend OTP Tokens (Email & SMS)
  • Retrieve User
  • Reset Password
  • Change User Data (e.g., Email or password)
  • SSO

Contributions

Contributors are always welcome. I only ask that you add or update tests to cover your changes. Until this crate reaches 1.0.0 we're in the "move fast and break things" phase. Don't concern yourself with elegance.

Dependencies

~4–16MB
~198K SLoC