diff --git a/Cargo.lock b/Cargo.lock index 4ea3978..812e5e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,7 +543,7 @@ dependencies = [ [[package]] name = "challenge_frontend" -version = "0.5.6" +version = "0.5.7" dependencies = [ "eframe", "egui", diff --git a/Cargo.toml b/Cargo.toml index 31a67d7..874564a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "challenge_frontend" -version = "0.5.6" +version = "0.5.7" edition = "2021" rust-version = "1.71" authors = ["Philip Barlow"] diff --git a/src/apps/login_app.rs b/src/apps/login_app.rs index 4f9e310..827f3a2 100644 --- a/src/apps/login_app.rs +++ b/src/apps/login_app.rs @@ -89,12 +89,12 @@ pub struct LoginApp { impl Default for LoginApp { fn default() -> Self { + let url = option_env!("BACKEND_URL").unwrap().to_string(); Self { + token_refresh_promise: refresh::submit_refresh(&url), login_promise: Default::default(), register_promise: Default::default(), - url: option_env!("BACKEND_URL") - .unwrap_or("http://123.4.5.6:3000/api/auth") - .to_string(), + url, login: LoginSchema { email: "admin@admin.com".to_string(), password: "password123".to_string(), @@ -105,7 +105,6 @@ impl Default for LoginApp { state: LoginState::LoggedOut, register: RegisterSchema::default(), toasts: Toasts::default(), - token_refresh_promise: None, } } } @@ -223,6 +222,7 @@ impl LoginApp { Ok(LoginState::Expired) => { self.state = LoginState::Expired; self.token_refresh_promise = refresh::submit_refresh(&self.url); + self.submit = Some(AuthRequest::Logout); } Err(e) => { self.toasts @@ -379,8 +379,10 @@ impl super::App for LoginApp { self.submit_login(ctx); } AuthRequest::Logout => { - log::debug!("Submitting logout request"); - self.submit_logout(ctx); + if self.register_promise.is_none() { + log::debug!("Submitting logout request"); + self.submit_logout(ctx); + } } AuthRequest::Register => { log::debug!("Submitting register request"); @@ -400,7 +402,6 @@ impl super::App for LoginApp { refresh::RefreshStatus::InProgress => {} refresh::RefreshStatus::Success => { self.state = LoginState::LoggedIn(self.login.email.clone()); - self.submit = Some(AuthRequest::Logout); } refresh::RefreshStatus::Failed(_) => { self.state = LoginState::LoggedOut; diff --git a/src/helpers/refresh.rs b/src/helpers/refresh.rs index 76b1430..2a35568 100644 --- a/src/helpers/refresh.rs +++ b/src/helpers/refresh.rs @@ -26,13 +26,10 @@ pub fn submit_refresh(url: &str) -> RefreshPromise { .send() .await .unwrap(); - let result = response + response .json::() .await - .map_err(|e| e.to_string()); - log::info!("Result: {:?}", result); - - result + .map_err(|e| e.to_string()) })) }