Skip to content

Commit

Permalink
Fixes a bug on the refresh-logout flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbrain-za committed Nov 5, 2023
1 parent e7df606 commit 554ca97
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/apps/login_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ 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
Expand Down Expand Up @@ -373,14 +372,31 @@ impl super::App for LoginApp {
"🔐 Login"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
match refresh::check_refresh_promise(&mut self.token_refresh_promise) {
refresh::RefreshStatus::InProgress => {}
refresh::RefreshStatus::Success => {
if self.state == LoginState::Expired {
self.submit = Some(AuthRequest::Logout);
}
self.state = LoginState::LoggedIn(self.login.email.clone());
}
refresh::RefreshStatus::Failed(_) => {
self.state = LoginState::LoggedOut;
self.submit = None;
}
_ => (),
}
self.check_login_promise();
self.check_register_promise();

if let Some(s) = &self.submit {
match s {
AuthRequest::Login => {
log::debug!("Submitting login request");
self.submit_login(ctx);
}
AuthRequest::Logout => {
if self.register_promise.is_none() {
if self.state != LoginState::LoggedOut {
log::debug!("Submitting logout request");
self.submit_logout(ctx);
}
Expand All @@ -396,19 +412,6 @@ impl super::App for LoginApp {
.open(open)
.default_height(500.0)
.show(ctx, |ui| self.ui(ui));
self.check_login_promise();
self.check_register_promise();

match refresh::check_refresh_promise(&mut self.token_refresh_promise) {
refresh::RefreshStatus::InProgress => {}
refresh::RefreshStatus::Success => {
self.state = LoginState::LoggedIn(self.login.email.clone());
}
refresh::RefreshStatus::Failed(_) => {
self.state = LoginState::LoggedOut;
}
_ => (),
}

self.toasts.show(ctx);
}
Expand Down

0 comments on commit 554ca97

Please sign in to comment.