Skip to content

Commit

Permalink
fix: missing auth_key for delete account api request
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Dec 19, 2024
1 parent af6b1c8 commit b51a711
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/models/ctx/update_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub fn update_profile<E: Env + 'static>(
Effects::none().unchanged()
}
}
Msg::Action(Action::Ctx(ActionCtx::DeleteAccount(password))) => match &profile.auth {
Some(_) => Effects::one(delete_account::<E>(password)).unchanged(),
Msg::Action(Action::Ctx(ActionCtx::DeleteAccount(password))) => match profile.auth_key() {
Some(auth_key) => Effects::one(delete_account::<E>(auth_key, password)).unchanged(),
_ => Effects::msg(Msg::Event(Event::Error {
error: CtxError::from(OtherError::UserNotLoggedIn),
source: Box::new(Event::UserAccountDeleted { uid: profile.uid() }),
Expand Down Expand Up @@ -390,7 +390,10 @@ pub fn update_profile<E: Env + 'static>(
}
}
}
Msg::Internal(Internal::DeleteAccountAPIResult(_, result)) => match result {
Msg::Internal(Internal::DeleteAccountAPIResult(
APIRequest::DeleteAccount { auth_key, .. },
result,
)) if profile.auth_key() == Some(auth_key) => match result {
Ok(_) => Effects::msg(Msg::Internal(Internal::Logout)).unchanged(),
Err(error) => Effects::msg(Msg::Event(Event::Error {
error: error.to_owned(),
Expand Down Expand Up @@ -507,8 +510,9 @@ fn push_profile_to_storage<E: Env + 'static>(profile: &Profile) -> Effect {
.into()
}

fn delete_account<E: Env + 'static>(password: &String) -> Effect {
fn delete_account<E: Env + 'static>(auth_key: &AuthKey, password: &String) -> Effect {
let request = APIRequest::DeleteAccount {
auth_key: auth_key.to_owned(),
password: password.to_owned(),
};
EffectFuture::Concurrent(
Expand Down
1 change: 1 addition & 0 deletions src/types/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum APIRequest {
},
#[serde(rename_all = "camelCase")]
DeleteAccount {
auth_key: AuthKey,
password: String,
},
#[serde(rename_all = "camelCase")]
Expand Down
5 changes: 3 additions & 2 deletions src/unit_tests/ctx/delete_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn actionctx_delete_account() {
url, method, body, ..
} if url == "https://api.strem.io/api/deleteUser"
&& method == "POST"
&& body == "{\"type\":\"DeleteAccount\",\"password\":\"password\"}" =>
&& body == "{\"type\":\"DeleteAccount\",\"authKey\":\"auth_key\",\"password\":\"password\"}" =>
{
future::ok(
Box::new(APIResult::Ok(SuccessResponse { success: True {} }))
Expand Down Expand Up @@ -138,7 +138,8 @@ fn actionctx_delete_account() {
Request {
url: "https://api.strem.io/api/deleteUser".to_owned(),
method: "POST".to_owned(),
body: "{\"type\":\"DeleteAccount\",\"password\":\"password\"}".to_owned(),
body: "{\"type\":\"DeleteAccount\",\"authKey\":\"auth_key\",\"password\":\"password\"}"
.to_owned(),
..Default::default()
},
"Delete account request has been sent"
Expand Down

0 comments on commit b51a711

Please sign in to comment.