Skip to content

Commit 3ede4b5

Browse files
authored
Merge pull request #41 from davidB/main
fix: take care of `should_create_user` when using LoginEmailOtpParams
2 parents 1b4ecfe + f44e52f commit 3ede4b5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/models.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ pub(crate) struct LoginWithEmailOtpPayload<'a> {
346346
pub(crate) options: Option<LoginEmailOtpParams>,
347347
}
348348

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

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

tests/client_tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,40 @@ async fn send_email_with_otp() {
150150
assert!(response.is_ok())
151151
}
152152

153+
#[tokio::test]
154+
async fn send_email_with_otp_with_create_user_false() {
155+
let auth_client = create_test_client();
156+
157+
let uuid = uuid::Uuid::now_v7();
158+
159+
let demo_email = format!("signup__{}@demo.com", uuid);
160+
161+
let data = serde_json::json!({
162+
"otp": format!("test" )
163+
});
164+
165+
let options = LoginEmailOtpParams {
166+
data: Some(data),
167+
should_create_user: Some(false),
168+
..Default::default()
169+
};
170+
171+
let response = auth_client
172+
.send_email_with_otp(&demo_email, Some(options))
173+
.await;
174+
175+
// Wait to prevent running into Supabase rate limits when running cargo test
176+
let one_minute = time::Duration::from_secs(60);
177+
thread::sleep(one_minute);
178+
179+
if let Err(Error::AuthError{status, message}) = response {
180+
assert_eq!(status.as_u16(), 422);
181+
assert!(message.contains("not allowed for otp"));
182+
} else {
183+
assert!(false, "Expected AuthError, got other response");
184+
}
185+
}
186+
153187
#[test]
154188
fn login_with_oauth_test() {
155189
let auth_client = create_test_client();

0 commit comments

Comments
 (0)