Skip to content

Commit 19ca02d

Browse files
committed
Updated error handling in login screen
1 parent d89ff00 commit 19ca02d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

GoInfoGame/GoInfoGame/Login/View/PosmLogin.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ struct PosmLoginView: View {
9494
} else {
9595
print("Missing credentials in Keychain")
9696
viewModel.hasLoginFailed = true
97+
viewModel.loginFailedMessage = "Invalid Credentials"
9798
}
9899

99100
case .failure(let message), .unavailable(let message):
100101
print("Biometric login failed: \(message)")
101102
viewModel.hasLoginFailed = true
103+
viewModel.loginFailedMessage = message
102104
}
103105
}
104106
}) {
@@ -109,7 +111,7 @@ struct PosmLoginView: View {
109111
}
110112

111113
if viewModel.hasLoginFailed {
112-
Text("Invalid Credentials")
114+
Text(viewModel.loginFailedMessage ?? "Invalid Credentials")
113115
.foregroundColor(.red)
114116
.padding(.top, 10)
115117
}
@@ -127,7 +129,7 @@ struct PosmLoginView: View {
127129
InitialView()
128130
}
129131
}
130-
.alert("Invalid Credentials", isPresented: $viewModel.shouldShowValidationAlert) {
132+
.alert(viewModel.errorMessage ?? "Invalid Credentials", isPresented: $viewModel.shouldShowValidationAlert) {
131133
Button("OK", role: .cancel) { }
132134
}
133135
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("SessionExpired"))) { notification in

GoInfoGame/GoInfoGame/Login/ViewModel/PosmLoginViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PosmLoginViewModel: ObservableObject {
1313
@Published var username: String = ""
1414
@Published var password: String = ""
1515
@Published var hasLoginFailed: Bool = false
16+
@Published var loginFailedMessage: String? = nil
1617
@Published var isLoginSuccess: Bool = false
1718
@Published var errorMessage: String?
1819
@Published var isLoading = false
@@ -28,6 +29,7 @@ class PosmLoginViewModel: ObservableObject {
2829
} else if password.isEmpty {
2930
errorMessage = "Password is required."
3031
} else {
32+
errorMessage = nil
3133
return true
3234
}
3335

0 commit comments

Comments
 (0)