mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
Merge pull request #1310 from AppFlowy-IO/recover
feat: client api for gotrue password recovery
This commit is contained in:
commit
e6f6a24b29
2 changed files with 23 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
use super::grant::Grant;
|
||||
use crate::params::{
|
||||
AdminDeleteUserParams, AdminUserParams, CreateSSOProviderParams, GenerateLinkParams,
|
||||
GenerateLinkResponse, InviteUserParams, MagicLinkParams, VerifyParams,
|
||||
GenerateLinkResponse, InviteUserParams, MagicLinkParams, RecoverParams, VerifyParams,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use gotrue_entity::dto::{
|
||||
|
@ -106,6 +106,23 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn recover(
|
||||
&self,
|
||||
recover_params: &RecoverParams,
|
||||
) -> Result<GotrueTokenResponse, GoTrueError> {
|
||||
let url = format!("{}/recover", self.base_url);
|
||||
let resp = self.client.post(url).json(recover_params).send().await?;
|
||||
if resp.status().is_success() {
|
||||
let token: GotrueTokenResponse = from_body(resp).await?;
|
||||
Ok(token)
|
||||
} else if resp.status().is_client_error() {
|
||||
Err(from_body::<GotrueClientError>(resp).await?.into())
|
||||
} else {
|
||||
Err(anyhow::anyhow!("unexpected response status: {}", resp.status()).into())
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn logout(&self, access_token: &str) -> Result<(), GoTrueError> {
|
||||
let url = format!("{}/logout", self.base_url);
|
||||
|
|
|
@ -135,3 +135,8 @@ pub struct VerifyParams {
|
|||
pub email: String,
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct RecoverParams {
|
||||
pub email: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue