Implement logout
This commit is contained in:
parent
47754aac27
commit
19cd44296a
4 changed files with 25 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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?";
|
||||
|
|
|
@ -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?";
|
||||
|
|
Loading…
Reference in a new issue