diff --git a/Twigs/DataStore.swift b/Twigs/DataStore.swift index 6eb5b2c..6e09051 100644 --- a/Twigs/DataStore.swift +++ b/Twigs/DataStore.swift @@ -408,6 +408,26 @@ class DataStore : ObservableObject { await self.login(username: username, password: password) } + func logout() { + self.budgets = .empty + self.budget = .empty + self.overview = .empty + self.categories = .empty + self.category = .empty + self.transactions = .empty + self.transaction = .empty + self.recurringTransactions = .empty + self.recurringTransaction = .empty + self.selectedRecurringTransaction = nil + self.selectedCategory = nil + self.selectedTransaction = nil + self.currentUser = .empty + self.user = .empty + self.token = nil + UserDefaults.standard.removeObject(forKey: KEY_TOKEN) + UserDefaults.standard.removeObject(forKey: KEY_USER_ID) + } + func loadProfile() async { guard let userId = self.userId, !userId.isEmpty else { self.currentUser = .error(UserStatus.unauthenticated) diff --git a/Twigs/TabbedBudgetView.swift b/Twigs/TabbedBudgetView.swift index b5fe9c6..38e5c00 100644 --- a/Twigs/TabbedBudgetView.swift +++ b/Twigs/TabbedBudgetView.swift @@ -25,7 +25,9 @@ struct TabbedBudgetView: View { Button("budgets", action: { self.dataStore.showBudgetSelection = true }).padding() - }) + }, trailing: Button("logout", action: { + self.dataStore.logout() + }).padding()) } .tabItem { Image(systemName: "chart.line.uptrend.xyaxis.circle.fill") diff --git a/Twigs/en.lproj/Localizable.strings b/Twigs/en.lproj/Localizable.strings index 128cd37..da6ff77 100644 --- a/Twigs/en.lproj/Localizable.strings +++ b/Twigs/en.lproj/Localizable.strings @@ -37,6 +37,7 @@ "prompt_password" = "Password"; "action_login" = "Login"; "loading_login" = "Logging in..."; +"logout" = "Logout"; // MARK: Registration "info_register" = "Don't have an account?"; diff --git a/Twigs/es.lproj/Localizable.strings b/Twigs/es.lproj/Localizable.strings index 2740da4..51591f3 100644 --- a/Twigs/es.lproj/Localizable.strings +++ b/Twigs/es.lproj/Localizable.strings @@ -37,6 +37,7 @@ "prompt_password" = "Contraseña"; "action_login" = "Inicia sesión"; "loading_login" = "Iniciando sesión..."; +"logout" = "Cerrar sesión"; // MARK: Registration "info_register" = "¿No tienes una cuenta?";