diff --git a/src/models.rs b/src/models.rs index cdaa220..e1c0b2f 100644 --- a/src/models.rs +++ b/src/models.rs @@ -346,6 +346,7 @@ pub(crate) struct LoginWithEmailOtpPayload<'a> { pub(crate) options: Option, } +// 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. @@ -355,9 +356,11 @@ pub struct LoginEmailOtpParams { /// The redirect url embedded in the email link pub email_redirect_to: Option, /// If set to false, this method will not create a new user. Defaults to true. + #[serde(rename = "create_user")] pub should_create_user: Option, } +// 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. @@ -367,6 +370,7 @@ pub struct LoginMobileOtpParams { /// The redirect url embedded in the email link pub channel: Option, /// If set to false, this method will not create a new user. Defaults to true. + #[serde(rename = "create_user")] pub should_create_user: Option, } diff --git a/tests/client_tests.rs b/tests/client_tests.rs index bd41ab3..dc569ef 100644 --- a/tests/client_tests.rs +++ b/tests/client_tests.rs @@ -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();