Implement logout

This commit is contained in:
William Brawner 2022-05-17 20:34:06 -06:00
parent 47754aac27
commit 19cd44296a
4 changed files with 25 additions and 1 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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?";

View file

@ -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?";