diff --git a/libs/client-api/src/http.rs b/libs/client-api/src/http.rs index 7d6e1585..48813f5e 100644 --- a/libs/client-api/src/http.rs +++ b/libs/client-api/src/http.rs @@ -215,6 +215,32 @@ impl Client { self.token.read().subscribe() } + /// Sign in with magic link + /// + /// User will receive an email with a magic link to sign in. + /// The redirect_to parameter is optional. If provided, the user will be redirected to the specified URL after signing in. + /// If not, the user will be redirected to the appflowy-flutter:// by default + /// + /// The redirect_to should be the scheme of the app, e.g., appflowy-flutter:// + #[instrument(level = "debug", skip_all, err)] + pub async fn sign_in_with_magic_link( + &self, + email: &str, + redirect_to: Option, + ) -> Result<(), AppResponseError> { + self + .gotrue_client + .magic_link( + &MagicLinkParams { + email: email.to_owned(), + ..Default::default() + }, + redirect_to, + ) + .await?; + Ok(()) + } + /// Attempts to sign in using a URL, extracting refresh_token from the URL. /// It looks like, e.g., `appflowy-flutter://#access_token=...&expires_in=3600&provider_token=...&refresh_token=...&token_type=bearer`. /// diff --git a/tests/user/sign_in.rs b/tests/user/sign_in.rs index 0d859409..59d2591c 100644 --- a/tests/user/sign_in.rs +++ b/tests/user/sign_in.rs @@ -101,3 +101,11 @@ async fn sign_in_with_url() { let is_new = c.sign_in_with_url(&sign_in_url).await.unwrap(); assert!(is_new); } + +#[tokio::test] +async fn sign_in_with_magic_link() { + let c = localhost_client(); + let email = generate_unique_email(); + let resp = c.sign_in_with_magic_link(&email, None).await; + assert!(resp.is_ok()); +}