Skip to content

Commit

Permalink
Updated Model Visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Proziam committed Oct 26, 2024
1 parent b7cb40b commit b25214a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
8 changes: 3 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
Session, SignInEmailOtpParams, SignInWithEmailAndPasswordPayload,
SignInWithEmailOtpPayload, SignInWithOAuthOptions, SignInWithPhoneAndPasswordPayload,
SignInWithSSO, SignUpWithEmailAndPasswordPayload, SignUpWithPasswordOptions,
SignUpWithPhoneAndPasswordPayload, UpdateUserPayload, User, VerifyOtpParams, AUTH_V1,
SignUpWithPhoneAndPasswordPayload, UpdatedUser, User, VerifyOtpParams, AUTH_V1,
},
};

Expand Down Expand Up @@ -275,8 +275,6 @@ impl AuthClient {
}
}

// TODO: Fix Return Type https://supabase.com/docs/reference/javascript/auth-signinwithotp

/// Send a Login OTP via SMS
///
/// # Example
Expand Down Expand Up @@ -463,7 +461,7 @@ impl AuthClient {
/// ```
pub async fn update_user(
&self,
updated_user: UpdateUserPayload,
updated_user: UpdatedUser,
bearer_token: &str,
) -> Result<User, Error> {
let mut headers = header::HeaderMap::new();
Expand All @@ -474,7 +472,7 @@ impl AuthClient {
HeaderValue::from_str(&format!("Bearer {}", bearer_token))?,
);

let body = serde_json::to_string::<UpdateUserPayload>(&updated_user)?;
let body = serde_json::to_string::<UpdatedUser>(&updated_user)?;

let response = self
.client
Expand Down
27 changes: 10 additions & 17 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,26 @@ pub enum LoginOptions {
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SignInWithEmailAndPasswordPayload<'a> {
pub(crate) struct SignInWithEmailAndPasswordPayload<'a> {
pub(crate) email: &'a str,
pub(crate) password: &'a str,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SignInWithPhoneAndPasswordPayload<'a> {
pub(crate) struct SignInWithPhoneAndPasswordPayload<'a> {
pub(crate) phone: &'a str,
pub(crate) password: &'a str,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SignUpWithEmailAndPasswordPayload<'a> {
pub(crate) struct SignUpWithEmailAndPasswordPayload<'a> {
pub(crate) email: &'a str,
pub(crate) password: &'a str,
pub(crate) options: Option<SignUpWithPasswordOptions>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SignUpWithPhoneAndPasswordPayload<'a> {
pub(crate) struct SignUpWithPhoneAndPasswordPayload<'a> {
pub(crate) phone: &'a str,
pub(crate) password: &'a str,
pub(crate) options: Option<SignUpWithPasswordOptions>,
Expand All @@ -188,19 +188,19 @@ pub struct SignUpWithPasswordOptions {
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RequestMagicLinkPayload<'a> {
pub(crate) struct RequestMagicLinkPayload<'a> {
pub(crate) email: &'a str,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UpdateUserPayload {
pub struct UpdatedUser {
pub email: Option<String>,
pub password: Option<String>,
pub data: Option<serde_json::Value>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SendSMSOtpPayload<'a> {
pub(crate) struct SendSMSOtpPayload<'a> {
pub phone: &'a str,
}

Expand Down Expand Up @@ -270,15 +270,8 @@ pub struct VerifyOtpOptions {
pub redirect_to: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum SignInWithOtp {
Mobile(SignInMobileOtpParams),
Email(SignInEmailOtpParams),
WhatsApp(SignInMobileOtpParams),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct SignInWithEmailOtpPayload<'a> {
pub(crate) struct SignInWithEmailOtpPayload<'a> {
pub email: &'a str,
pub options: Option<SignInEmailOtpParams>,
}
Expand Down Expand Up @@ -316,12 +309,12 @@ pub struct SignInMobileOtpParams {
}

#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RefreshSessionPayload<'a> {
pub(crate) struct RefreshSessionPayload<'a> {
pub refresh_token: &'a str,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResetPasswordForEmailPayload {
pub(crate) struct ResetPasswordForEmailPayload {
pub email: String,
}

Expand Down
6 changes: 3 additions & 3 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashMap, env, thread};

use supabase_auth::models::{
AuthClient, LogoutScope, ResendParams, SignInWithOAuthOptions, SignInWithSSO,
SignUpWithPasswordOptions, UpdateUserPayload,
SignUpWithPasswordOptions, UpdatedUser,
};

fn create_test_client() -> AuthClient {
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn update_user_test() {

eprintln!("{:?}", session);

let updated_user = UpdateUserPayload {
let updated_user = UpdatedUser {
email: Some(demo_email.clone()),
password: Some("qqqqwwww".to_string()),
data: None,
Expand All @@ -272,7 +272,7 @@ async fn update_user_test() {
}

// Return the user to original condition
let original_user = UpdateUserPayload {
let original_user = UpdatedUser {
email: Some(demo_email),
password: Some("qwerqwer".to_string()),
data: None,
Expand Down

0 comments on commit b25214a

Please sign in to comment.