mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
Merge pull request #1309 from AppFlowy-IO/add-verify-endpoint-gotrue
feat: add client api for gotrue verify endpoint
This commit is contained in:
commit
0f590c5a7b
2 changed files with 32 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
use super::grant::Grant;
|
||||
use crate::params::{
|
||||
AdminDeleteUserParams, AdminUserParams, CreateSSOProviderParams, GenerateLinkParams,
|
||||
GenerateLinkResponse, InviteUserParams, MagicLinkParams,
|
||||
GenerateLinkResponse, InviteUserParams, MagicLinkParams, VerifyParams,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use gotrue_entity::dto::{
|
||||
|
@ -89,6 +89,23 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn verify(
|
||||
&self,
|
||||
verify_params: &VerifyParams,
|
||||
) -> Result<GotrueTokenResponse, GoTrueError> {
|
||||
let url = format!("{}/verify", self.base_url);
|
||||
let resp = self.client.post(url).json(verify_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);
|
||||
|
|
|
@ -121,3 +121,17 @@ pub struct CreateSSOProviderParams {
|
|||
pub domains: Vec<String>,
|
||||
pub attribute_mapping: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum VerifyType {
|
||||
Recovery,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct VerifyParams {
|
||||
#[serde(rename = "type")]
|
||||
pub type_: VerifyType,
|
||||
pub email: String,
|
||||
pub token: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue