feat: support name for oauth sign in (#65)
* feat: support name for oauth sign in * fix: add sqlx metadata * feat: improve api, add name modifications * fix: add sqlx query metadata
This commit is contained in:
parent
ca0813e265
commit
bbc913e45f
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n INSERT INTO af_user (uuid, email)\n SELECT $1, $2\n WHERE NOT EXISTS (\n SELECT 1 FROM public.af_user WHERE email = $2\n )\n AND NOT EXISTS (\n SELECT 1 FROM public.af_user WHERE uuid = $1\n )\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid",
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "4cd579c6421d05807fb8433d14ea312db0977353e34ef04e2bab31e009151bb2"
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO af_user (uuid, email, name)\n SELECT $1, $2, $3\n WHERE NOT EXISTS (\n SELECT 1 FROM public.af_user WHERE email = $2\n )\n AND NOT EXISTS (\n SELECT 1 FROM public.af_user WHERE uuid = $1\n )\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid",
|
||||||
|
"Text",
|
||||||
|
"Text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "6bbb6f2e06a63df25a7a50624f1931b50c481f29a36b0f9264c1c1d4439f5935"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n UPDATE af_user\n SET name = $1\n WHERE uuid = $2\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Text",
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "d9003caf83e3c1d85e9a2b732c1d1853e919f5af088d9e670b507599fc0fb331"
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@ use gotrue_entity::OAuthURL;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use reqwest::RequestBuilder;
|
use reqwest::RequestBuilder;
|
||||||
use shared_entity::data::AppResponse;
|
use shared_entity::data::AppResponse;
|
||||||
|
use shared_entity::dto::SignInParams;
|
||||||
|
use shared_entity::dto::UserUpdateParams;
|
||||||
use shared_entity::dto::WorkspaceMembersParams;
|
use shared_entity::dto::WorkspaceMembersParams;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use storage_entity::AFWorkspaceMember;
|
use storage_entity::AFWorkspaceMember;
|
||||||
|
|
@ -205,11 +207,11 @@ impl Client {
|
||||||
|
|
||||||
pub async fn sign_in_password(&mut self, email: &str, password: &str) -> Result<(), AppError> {
|
pub async fn sign_in_password(&mut self, email: &str, password: &str) -> Result<(), AppError> {
|
||||||
let url = format!("{}/api/user/sign_in/password", self.base_url);
|
let url = format!("{}/api/user/sign_in/password", self.base_url);
|
||||||
let payload = serde_json::json!({
|
let params = SignInParams {
|
||||||
"email": email,
|
email: email.to_owned(),
|
||||||
"password": password,
|
password: password.to_owned(),
|
||||||
});
|
};
|
||||||
let resp = self.http_client.post(&url).json(&payload).send().await?;
|
let resp = self.http_client.post(&url).json(¶ms).send().await?;
|
||||||
self
|
self
|
||||||
.token
|
.token
|
||||||
.set(AppResponse::from_response(resp).await?.into_data()?);
|
.set(AppResponse::from_response(resp).await?.into_data()?);
|
||||||
|
|
@ -233,11 +235,11 @@ impl Client {
|
||||||
|
|
||||||
pub async fn sign_up(&self, email: &str, password: &str) -> Result<(), AppError> {
|
pub async fn sign_up(&self, email: &str, password: &str) -> Result<(), AppError> {
|
||||||
let url = format!("{}/api/user/sign_up", self.base_url);
|
let url = format!("{}/api/user/sign_up", self.base_url);
|
||||||
let payload = serde_json::json!({
|
let params = SignInParams {
|
||||||
"email": email,
|
email: email.to_owned(),
|
||||||
"password": password,
|
password: password.to_owned(),
|
||||||
});
|
};
|
||||||
let resp = self.http_client.post(&url).json(&payload).send().await?;
|
let resp = self.http_client.post(&url).json(¶ms).send().await?;
|
||||||
AppResponse::<()>::from_response(resp).await?.into_error()?;
|
AppResponse::<()>::from_response(resp).await?.into_error()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -254,16 +256,22 @@ impl Client {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(&mut self, email: &str, password: &str) -> Result<(), AppError> {
|
pub async fn update(
|
||||||
|
&mut self,
|
||||||
|
email: &str,
|
||||||
|
password: &str,
|
||||||
|
name: Option<&str>,
|
||||||
|
) -> Result<(), AppError> {
|
||||||
let url = format!("{}/api/user/update", self.base_url);
|
let url = format!("{}/api/user/update", self.base_url);
|
||||||
let payload = serde_json::json!({
|
let params = UserUpdateParams {
|
||||||
"email": email,
|
email: email.to_owned(),
|
||||||
"password": password,
|
password: password.to_owned(),
|
||||||
});
|
name: name.map(String::from),
|
||||||
|
};
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::POST, &url)
|
.http_client_with_auth(Method::POST, &url)
|
||||||
.await?
|
.await?
|
||||||
.json(&payload)
|
.json(¶ms)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
let new_user = AppResponse::<User>::from_response(resp)
|
let new_user = AppResponse::<User>::from_response(resp)
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,16 @@ pub struct WorkspaceMembersParams {
|
||||||
pub workspace_uuid: uuid::Uuid,
|
pub workspace_uuid: uuid::Uuid,
|
||||||
pub member_emails: Vec<String>,
|
pub member_emails: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct SignInParams {
|
||||||
|
pub email: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct UserUpdateParams {
|
||||||
|
pub email: String,
|
||||||
|
pub password: String,
|
||||||
|
pub name: Option<String>,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,35 @@ use sqlx::{
|
||||||
|
|
||||||
use storage_entity::{AFRole, AFUserProfileView, AFWorkspace, AFWorkspaceMember};
|
use storage_entity::{AFRole, AFUserProfileView, AFWorkspace, AFWorkspaceMember};
|
||||||
|
|
||||||
|
pub async fn update_user_name(
|
||||||
|
pool: &PgPool,
|
||||||
|
gotrue_uuid: &uuid::Uuid,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
sqlx::query!(
|
||||||
|
r#"
|
||||||
|
UPDATE af_user
|
||||||
|
SET name = $1
|
||||||
|
WHERE uuid = $2
|
||||||
|
"#,
|
||||||
|
name,
|
||||||
|
gotrue_uuid
|
||||||
|
)
|
||||||
|
.execute(pool)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create_user_if_not_exists(
|
pub async fn create_user_if_not_exists(
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
gotrue_uuid: &uuid::Uuid,
|
gotrue_uuid: &uuid::Uuid,
|
||||||
email: &str,
|
email: &str,
|
||||||
|
name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO af_user (uuid, email)
|
INSERT INTO af_user (uuid, email, name)
|
||||||
SELECT $1, $2
|
SELECT $1, $2, $3
|
||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT 1 FROM public.af_user WHERE email = $2
|
SELECT 1 FROM public.af_user WHERE email = $2
|
||||||
)
|
)
|
||||||
|
|
@ -22,7 +42,8 @@ pub async fn create_user_if_not_exists(
|
||||||
)
|
)
|
||||||
"#,
|
"#,
|
||||||
gotrue_uuid,
|
gotrue_uuid,
|
||||||
email
|
email,
|
||||||
|
name
|
||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use crate::domain::{UserEmail, UserName, UserPassword};
|
||||||
use crate::state::AppState;
|
use crate::state::AppState;
|
||||||
use gotrue_entity::{AccessTokenResponse, OAuthProvider, OAuthURL, User};
|
use gotrue_entity::{AccessTokenResponse, OAuthProvider, OAuthURL, User};
|
||||||
use shared_entity::data::{AppResponse, JsonAppResponse};
|
use shared_entity::data::{AppResponse, JsonAppResponse};
|
||||||
|
use shared_entity::dto::{SignInParams, UserUpdateParams};
|
||||||
use shared_entity::error::AppError;
|
use shared_entity::error::AppError;
|
||||||
use shared_entity::error_code::ErrorCode;
|
use shared_entity::error_code::ErrorCode;
|
||||||
use storage_entity::AFUserProfileView;
|
use storage_entity::AFUserProfileView;
|
||||||
|
|
@ -77,12 +78,19 @@ async fn profile_handler(
|
||||||
|
|
||||||
async fn update_handler(
|
async fn update_handler(
|
||||||
auth: Authorization,
|
auth: Authorization,
|
||||||
req: Json<LoginRequest>,
|
req: Json<UserUpdateParams>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
) -> Result<JsonAppResponse<User>> {
|
) -> Result<JsonAppResponse<User>> {
|
||||||
let req = req.into_inner();
|
let req = req.into_inner();
|
||||||
let user =
|
let user = biz::user::update(
|
||||||
biz::user::update(&state.gotrue_client, &auth.token, &req.email, &req.password).await?;
|
&state.pg_pool,
|
||||||
|
&state.gotrue_client,
|
||||||
|
&auth.token,
|
||||||
|
&req.email,
|
||||||
|
&req.password,
|
||||||
|
req.name.as_deref(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(AppResponse::Ok().with_data(user).into())
|
Ok(AppResponse::Ok().with_data(user).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +108,7 @@ async fn sign_out_handler(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sign_in_password_handler(
|
async fn sign_in_password_handler(
|
||||||
req: Json<LoginRequest>,
|
req: Json<SignInParams>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
) -> Result<JsonAppResponse<AccessTokenResponse>> {
|
) -> Result<JsonAppResponse<AccessTokenResponse>> {
|
||||||
let req = req.into_inner();
|
let req = req.into_inner();
|
||||||
|
|
@ -116,14 +124,15 @@ async fn sign_in_password_handler(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sign_up_handler(
|
async fn sign_up_handler(
|
||||||
req: Json<LoginRequest>,
|
req: Json<SignInParams>,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
) -> Result<JsonAppResponse<()>> {
|
) -> Result<JsonAppResponse<()>> {
|
||||||
|
let req = req.into_inner();
|
||||||
biz::user::sign_up(
|
biz::user::sign_up(
|
||||||
&state.gotrue_client,
|
|
||||||
&req.email,
|
|
||||||
&req.password,
|
|
||||||
&state.pg_pool,
|
&state.pg_pool,
|
||||||
|
&state.gotrue_client,
|
||||||
|
req.email,
|
||||||
|
req.password,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,17 @@ pub async fn refresh(
|
||||||
|
|
||||||
#[instrument(level = "info", skip_all, err)]
|
#[instrument(level = "info", skip_all, err)]
|
||||||
pub async fn sign_up(
|
pub async fn sign_up(
|
||||||
gotrue_client: &Client,
|
|
||||||
email: &str,
|
|
||||||
password: &str,
|
|
||||||
pg_pool: &PgPool,
|
pg_pool: &PgPool,
|
||||||
|
gotrue_client: &Client,
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
validate_email_password(email, password)?;
|
validate_email_password(&email, &password)?;
|
||||||
let user = gotrue_client.sign_up(email, password).await??;
|
let user = gotrue_client.sign_up(&email, &password).await??;
|
||||||
tracing::info!("user sign up: {:?}", user);
|
tracing::info!("user sign up: {:?}", user);
|
||||||
if user.confirmed_at.is_some() {
|
if user.confirmed_at.is_some() {
|
||||||
let gotrue_uuid = uuid::Uuid::from_str(&user.id)?;
|
let gotrue_uuid = uuid::Uuid::from_str(&user.id)?;
|
||||||
storage::workspace::create_user_if_not_exists(pg_pool, &gotrue_uuid, &user.email).await?;
|
storage::workspace::create_user_if_not_exists(pg_pool, &gotrue_uuid, &user.email, "").await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,8 @@ pub async fn info(
|
||||||
) -> Result<User, AppError> {
|
) -> Result<User, AppError> {
|
||||||
let user = gotrue_client.user_info(access_token).await??;
|
let user = gotrue_client.user_info(access_token).await??;
|
||||||
let user_uuid = uuid::Uuid::from_str(&user.id)?;
|
let user_uuid = uuid::Uuid::from_str(&user.id)?;
|
||||||
storage::workspace::create_user_if_not_exists(pg_pool, &user_uuid, &user.email).await?;
|
let name: String = name_from_user_metadata(&user.user_metadata);
|
||||||
|
storage::workspace::create_user_if_not_exists(pg_pool, &user_uuid, &user.email, &name).await?;
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,20 +89,26 @@ pub async fn sign_in(
|
||||||
) -> Result<AccessTokenResponse, AppError> {
|
) -> Result<AccessTokenResponse, AppError> {
|
||||||
let grant = Grant::Password(PasswordGrant { email, password });
|
let grant = Grant::Password(PasswordGrant { email, password });
|
||||||
let token = gotrue_client.token(&grant).await??;
|
let token = gotrue_client.token(&grant).await??;
|
||||||
|
|
||||||
let gotrue_uuid = uuid::Uuid::from_str(&token.user.id)?;
|
let gotrue_uuid = uuid::Uuid::from_str(&token.user.id)?;
|
||||||
storage::workspace::create_user_if_not_exists(pg_pool, &gotrue_uuid, &token.user.email).await?;
|
storage::workspace::create_user_if_not_exists(pg_pool, &gotrue_uuid, &token.user.email, "")
|
||||||
|
.await?;
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
|
pg_pool: &PgPool,
|
||||||
gotrue_client: &Client,
|
gotrue_client: &Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
email: &str,
|
email: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
|
name: Option<&str>,
|
||||||
) -> Result<User, AppError> {
|
) -> Result<User, AppError> {
|
||||||
validate_email_password(email, password)?;
|
validate_email_password(email, password)?;
|
||||||
let user = gotrue_client.update_user(token, email, password).await??;
|
let user = gotrue_client.update_user(token, email, password).await??;
|
||||||
|
let user_uuid = user.id.parse::<uuid::Uuid>()?;
|
||||||
|
if let Some(name) = name {
|
||||||
|
storage::workspace::update_user_name(pg_pool, &user_uuid, name).await?;
|
||||||
|
}
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,3 +121,14 @@ fn validate_email_password(email: &str, password: &str) -> Result<(), AppError>
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Best effort to get user's name after oauth
|
||||||
|
fn name_from_user_metadata(value: &serde_json::Value) -> String {
|
||||||
|
value
|
||||||
|
.get("name")
|
||||||
|
.or(value.get("full_name"))
|
||||||
|
.or(value.get("nickname"))
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.map(str::to_string)
|
||||||
|
.unwrap_or(String::new())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
|
||||||
|
|
||||||
use secrecy::ExposeSecret;
|
use secrecy::ExposeSecret;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::types::uuid;
|
use sqlx::types::{uuid, Uuid};
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::state::AppState;
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
|
@ -19,21 +20,7 @@ pub struct UserUuid(uuid::Uuid);
|
||||||
|
|
||||||
impl UserUuid {
|
impl UserUuid {
|
||||||
pub fn from_auth(auth: Authorization) -> Result<Self, actix_web::Error> {
|
pub fn from_auth(auth: Authorization) -> Result<Self, actix_web::Error> {
|
||||||
let uuid = auth
|
Ok(Self(auth.uuid()?))
|
||||||
.claims
|
|
||||||
.sub
|
|
||||||
.ok_or(actix_web::error::ErrorUnauthorized(
|
|
||||||
"Invalid Authorization header, missing sub(uuid)",
|
|
||||||
))
|
|
||||||
.map(|sub| {
|
|
||||||
uuid::Uuid::parse_str(&sub).map_err(|e| {
|
|
||||||
actix_web::error::ErrorUnauthorized(format!(
|
|
||||||
"Invalid Authorization header, invalid sub(uuid): {}",
|
|
||||||
e
|
|
||||||
))
|
|
||||||
})
|
|
||||||
})?;
|
|
||||||
Ok(Self(uuid?))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,8 +70,21 @@ pub struct Authorization {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Authorization {
|
impl Authorization {
|
||||||
pub fn uuid(&self) -> Option<String> {
|
pub fn uuid(&self) -> Result<uuid::Uuid, actix_web::Error> {
|
||||||
self.claims.sub.clone()
|
self
|
||||||
|
.claims
|
||||||
|
.sub
|
||||||
|
.as_deref()
|
||||||
|
.map(Uuid::from_str)
|
||||||
|
.ok_or(actix_web::error::ErrorUnauthorized(
|
||||||
|
"Invalid Authorization header, missing sub(uuid)",
|
||||||
|
))?
|
||||||
|
.map_err(|e| {
|
||||||
|
actix_web::error::ErrorUnauthorized(format!(
|
||||||
|
"Invalid Authorization header, invalid sub(uuid): {}",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ async fn sign_in_wrong_password() {
|
||||||
|
|
||||||
let email = generate_unique_email();
|
let email = generate_unique_email();
|
||||||
let password = "Hello123!";
|
let password = "Hello123!";
|
||||||
|
|
||||||
c.sign_up(&email, password).await.unwrap();
|
c.sign_up(&email, password).await.unwrap();
|
||||||
|
|
||||||
let wrong_password = "Hllo123!";
|
let wrong_password = "Hllo123!";
|
||||||
|
|
@ -37,7 +36,6 @@ async fn sign_in_unconfirmed_email() {
|
||||||
|
|
||||||
let email = generate_unique_email();
|
let email = generate_unique_email();
|
||||||
let password = "Hello123!";
|
let password = "Hello123!";
|
||||||
|
|
||||||
c.sign_up(&email, password).await.unwrap();
|
c.sign_up(&email, password).await.unwrap();
|
||||||
|
|
||||||
let err = c.sign_in_password(&email, password).await.unwrap_err();
|
let err = c.sign_in_password(&email, password).await.unwrap_err();
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,10 @@ async fn sign_up_success() {
|
||||||
async fn sign_up_invalid_email() {
|
async fn sign_up_invalid_email() {
|
||||||
let invalid_email = "not_email_address";
|
let invalid_email = "not_email_address";
|
||||||
let password = "Hello!123#";
|
let password = "Hello!123#";
|
||||||
let c = client_api_client();
|
let error = client_api_client()
|
||||||
let error = c.sign_up(invalid_email, password).await.unwrap_err();
|
.sign_up(invalid_email, password)
|
||||||
|
.await
|
||||||
|
.unwrap_err();
|
||||||
assert_eq!(error.code, ErrorCode::InvalidEmail);
|
assert_eq!(error.code, ErrorCode::InvalidEmail);
|
||||||
assert_eq!(error.message, "invalid email: not_email_address");
|
assert_eq!(error.message, "invalid email: not_email_address");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ async fn update_but_not_logged_in() {
|
||||||
let mut c = client_api_client();
|
let mut c = client_api_client();
|
||||||
let new_email = generate_unique_email();
|
let new_email = generate_unique_email();
|
||||||
let new_password = "Hello123!";
|
let new_password = "Hello123!";
|
||||||
let res = c.update(&new_email, new_password).await;
|
let res = c.update(&new_email, new_password, None).await;
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,11 @@ async fn update_password_same_password() {
|
||||||
c.sign_in_password(&user.email, &user.password)
|
c.sign_in_password(&user.email, &user.password)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let err = c.update(&user.email, &user.password).await.err().unwrap();
|
let err = c
|
||||||
|
.update(&user.email, &user.password, None)
|
||||||
|
.await
|
||||||
|
.err()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(err.code, ErrorCode::InvalidPassword);
|
assert_eq!(err.code, ErrorCode::InvalidPassword);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.message,
|
err.message,
|
||||||
|
|
@ -41,12 +45,12 @@ async fn update_password_and_revert() {
|
||||||
c.sign_in_password(&user.email, &user.password)
|
c.sign_in_password(&user.email, &user.password)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
c.update(&user.email, new_password).await.unwrap();
|
c.update(&user.email, new_password, None).await.unwrap();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// revert password to old_password
|
// revert password to old_password
|
||||||
let mut c = client_api_client();
|
let mut c = client_api_client();
|
||||||
c.sign_in_password(&user.email, new_password).await.unwrap();
|
c.sign_in_password(&user.email, new_password).await.unwrap();
|
||||||
c.update(&user.email, &user.password).await.unwrap();
|
c.update(&user.email, &user.password, None).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue