Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub(crate) struct LoginWithEmailOtpPayload<'a> {
pub(crate) options: Option<LoginEmailOtpParams>,
}

// align json field's name with https://github.com/supabase/auth/blob/1f7de6c65f31ef0bbb80899369989b13ab5a517f/openapi.yaml#L559
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct LoginEmailOtpParams {
/// Verification token received when the user completes the captcha on the site.
Expand All @@ -355,9 +356,11 @@ pub struct LoginEmailOtpParams {
/// The redirect url embedded in the email link
pub email_redirect_to: Option<String>,
/// If set to false, this method will not create a new user. Defaults to true.
#[serde(rename = "create_user")]
pub should_create_user: Option<bool>,
}

// align json field's name with https://github.com/supabase/auth/blob/1f7de6c65f31ef0bbb80899369989b13ab5a517f/openapi.yaml#L559
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct LoginMobileOtpParams {
/// Verification token received when the user completes the captcha on the site.
Expand All @@ -367,6 +370,7 @@ pub struct LoginMobileOtpParams {
/// The redirect url embedded in the email link
pub channel: Option<Channel>,
/// If set to false, this method will not create a new user. Defaults to true.
#[serde(rename = "create_user")]
pub should_create_user: Option<bool>,
}

Expand Down
34 changes: 34 additions & 0 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ async fn send_email_with_otp() {
assert!(response.is_ok())
}

#[tokio::test]
async fn send_email_with_otp_with_create_user_false() {
let auth_client = create_test_client();

let uuid = uuid::Uuid::now_v7();

let demo_email = format!("signup__{}@demo.com", uuid);

let data = serde_json::json!({
"otp": format!("test" )
});

let options = LoginEmailOtpParams {
data: Some(data),
should_create_user: Some(false),
..Default::default()
};

let response = auth_client
.send_email_with_otp(&demo_email, Some(options))
.await;

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

if let Err(Error::AuthError{status, message}) = response {
assert_eq!(status.as_u16(), 422);
assert!(message.contains("not allowed for otp"));
} else {
assert!(false, "Expected AuthError, got other response");
}
}

#[test]
fn login_with_oauth_test() {
let auth_client = create_test_client();
Expand Down