Merge pull request #1309 from AppFlowy-IO/add-verify-endpoint-gotrue

feat: add client api for gotrue verify endpoint
This commit is contained in:
Khor Shu Heng 2025-04-01 15:46:59 +08:00 committed by GitHub
commit 0f590c5a7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View file

@ -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);

View file

@ -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,
}