pub struct AdminAuth { /* private fields */ }
Expand description
Auth Admin クライアント - 管理者用API
Implementations§
Source§impl AdminAuth
impl AdminAuth
Sourcepub fn new(url: &str, service_role_key: &str, http_client: Client) -> Self
pub fn new(url: &str, service_role_key: &str, http_client: Client) -> Self
新しいAdminAuthクライアントを作成
Sourcepub async fn get_user_by_id(&self, user_id: &str) -> Result<User, AuthError>
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");
}
Sourcepub async fn list_users(
&self,
page: Option<u32>,
per_page: Option<u32>,
) -> Result<Vec<User>, AuthError>
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");
}
Sourcepub async fn create_user(
&self,
email: &str,
password: Option<&str>,
user_metadata: Option<Value>,
email_confirm: Option<bool>,
) -> Result<User, AuthError>
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");
}
Sourcepub async fn delete_user(&self, user_id: &str) -> Result<(), AuthError>
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");
}
Sourcepub async fn update_user(
&self,
user_id: &str,
attributes: Value,
) -> Result<User, AuthError>
pub async fn update_user( &self, user_id: &str, attributes: Value, ) -> Result<User, AuthError>
ユーザーの情報を更新します
§引数
user_id
- 更新するユーザーのIDattributes
- 更新するユーザー属性(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");
}
Sourcepub async fn invite_user_by_email(
&self,
email: &str,
redirect_to: Option<&str>,
) -> Result<User, AuthError>
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");
}
Sourcepub async fn delete_user_factor(
&self,
user_id: &str,
factor_id: &str,
) -> Result<(), AuthError>
pub async fn delete_user_factor( &self, user_id: &str, factor_id: &str, ) -> Result<(), AuthError>
ユーザーのMFAファクターを削除します
§引数
user_id
- ユーザーのIDfactor_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");
}
Sourcepub async fn generate_link(
&self,
email: &str,
link_type: &str,
redirect_to: Option<&str>,
) -> Result<String, AuthError>
pub async fn generate_link( &self, email: &str, link_type: &str, redirect_to: Option<&str>, ) -> Result<String, AuthError>
メールリンクを生成します (マジックリンク, パスワードリセットなど)
§引数
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§
impl Freeze for AdminAuth
impl !RefUnwindSafe for AdminAuth
impl Send for AdminAuth
impl Sync for AdminAuth
impl Unpin for AdminAuth
impl !UnwindSafe for AdminAuth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more