Merge pull request #459 from LucasXu0/magic_link
feat: expose magic link api
This commit is contained in:
commit
dd9cc8d4c7
|
|
@ -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<String>,
|
||||
) -> 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`.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue