Struct AdminAuth

Source
pub struct AdminAuth { /* private fields */ }
Expand description

Auth Admin クライアント - 管理者用API

Implementations§

Source§

impl AdminAuth

Source

pub fn new(url: &str, service_role_key: &str, http_client: Client) -> Self

新しいAdminAuthクライアントを作成

Source

pub async fn get_user_by_id(&self, user_id: &str) -> Result<User, AuthError>

Gets a user by their ID.

§Example
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let user = admin_auth.get_user_by_id("some-user-id").await?;
    println!("User: {:?}", user);
} else {
    println!("Admin client not initialized");
}
Source

pub async fn list_users( &self, page: Option<u32>, per_page: Option<u32>, ) -> Result<Vec<User>, AuthError>

Lists users with pagination.

§Example
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let users = admin_auth.list_users(Some(1), Some(100)).await?;
    println!("Users: {:?}", users);
} else {
    println!("Admin client not initialized");
}
Source

pub async fn create_user( &self, email: &str, password: Option<&str>, user_metadata: Option<Value>, email_confirm: Option<bool>, ) -> Result<User, AuthError>

新しいユーザーを作成します

§引数
  • email - ユーザーのEメールアドレス
  • password - ユーザーのパスワード(オプション)
  • user_metadata - ユーザーのメタデータ(オプション)
  • email_confirm - メールアドレスを確認済みとしてマークするかどうか(オプション、デフォルトはfalse)
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let metadata = serde_json::json!({
        "first_name": "John",
        "last_name": "Doe"
    });

    let user = admin_auth.create_user(
        "user@example.com",
        Some("password123"),
        Some(metadata),
        Some(true)
    ).await?;
    println!("Created user: {:?}", user);
} else {
    println!("Admin client not initialized");
}
Source

pub async fn delete_user(&self, user_id: &str) -> Result<(), AuthError>

ユーザーを削除します

§引数
  • user_id - 削除するユーザーのID
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    admin_auth.delete_user("some-user-id").await?;
    println!("User deleted");
} else {
    println!("Admin client not initialized");
}
Source

pub async fn update_user( &self, user_id: &str, attributes: Value, ) -> Result<User, AuthError>

ユーザーの情報を更新します

§引数
  • user_id - 更新するユーザーのID
  • attributes - 更新するユーザー属性(email, password, user_metadata, email_confirm, phone_confirm など)
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let attributes = serde_json::json!({
        "email": "newemail@example.com",
        "user_metadata": {
            "first_name": "Jane",
            "last_name": "Smith"
        },
        "email_confirm": true
    });

    let user = admin_auth.update_user(
        "some-user-id",
        attributes
    ).await?;
    println!("Updated user: {:?}", user);
} else {
    println!("Admin client not initialized");
}
Source

pub async fn invite_user_by_email( &self, email: &str, redirect_to: Option<&str>, ) -> Result<User, AuthError>

メール招待リンクを送信します

§引数
  • email - 招待するユーザーのEメールアドレス
  • redirect_to - 認証後のリダイレクト先URL(オプション)
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let user = admin_auth.invite_user_by_email(
        "user@example.com",
        Some("https://your-app.com/welcome")
    ).await?;
    println!("Invited user: {:?}", user);
} else {
    println!("Admin client not initialized");
}
Source

pub async fn delete_user_factor( &self, user_id: &str, factor_id: &str, ) -> Result<(), AuthError>

ユーザーのMFAファクターを削除します

§引数
  • user_id - ユーザーのID
  • factor_id - 削除するMFAファクターのID
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    admin_auth.delete_user_factor(
        "some-user-id",
        "factor-id"
    ).await?;
    println!("User factor deleted");
} else {
    println!("Admin client not initialized");
}

メールリンクを生成します (マジックリンク, パスワードリセットなど)

§引数
  • email - ユーザーのEメールアドレス
  • type - リンクの種類 (“signup”, “magiclink”, “recovery”, “invite”)
  • redirect_to - 認証後のリダイレクト先URL(オプション)
§
let mut auth = Auth::new("https://example.supabase.co/auth/v1", "anon-key", Client::new(), AuthOptions::default());

// Initialize the admin client using a service role key
let auth = auth.init_admin("your-service-role-key");

if let Some(admin_auth) = auth.admin() {
    let link = admin_auth.generate_link(
        "user@example.com",
        "magiclink",
        Some("https://your-app.com/welcome")
    ).await?;
    println!("Generated link: {}", link);
} else {
    println!("Admin client not initialized");
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T