Skip to content

Commit 1ec95fb

Browse files
authored
fix(Authenticator): Adding new error localizations for limits exceeded (#96)
1 parent 068bd3c commit 1ec95fb

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.1.8 (2024-09-20)
4+
5+
### Bug Fixes
6+
- **Authenticator**: Adding new error localizations for limits exceeded (#96)
7+
38
## 1.1.7 (2024-09-13)
49

510
### Bug Fixes

Sources/Authenticator/Constants/ComponentInformation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
import Foundation
99

1010
public class ComponentInformation {
11-
public static let version = "1.1.7"
11+
public static let version = "1.1.8"
1212
public static let name = "amplify-ui-swift-authenticator"
1313
}

Sources/Authenticator/Resources/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164

165165
/* Authenticator Errors */
166166
"authenticator.authError.incorrectCredentials" = "Incorrect username or password";
167+
"authenticator.authError.passwordAttemptsExceeded" = "You've reached the password attempts limit. Please try again later";
167168
"authenticator.authError.continueSignInWithMFASelection.noSelectionError" = "Please select an MFA method to continue";
168169
"authenticator.unknownError" = "Sorry, something went wrong";
169170

@@ -174,6 +175,7 @@
174175
"authenticator.cognitoError.network" = "Please check your connectivity";
175176
"authenticator.cognitoError.usernameExists" = "Username already exists";
176177
"authenticator.cognitoError.userNotFound" = "User not found";
178+
"authenticator.cognitoError.limitExceeded" = "You've reached the request limit. Please try again later";
177179

178180
/* Toolbar displayed on top of the keyboard */
179181
"authenticator.keyboardToolbar.Done" = "Done";

Sources/Authenticator/States/AuthenticatorBaseState.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,13 @@ public class AuthenticatorBaseState: ObservableObject {
197197
}
198198

199199
private func localizedMessage(for error: AuthError) -> String? {
200-
if case .notAuthorized(_, _, _) = error {
201-
return "authenticator.authError.incorrectCredentials".localized()
200+
if case .notAuthorized(let description, _, _) = error {
201+
switch description {
202+
case "Password attempts exceeded":
203+
return "authenticator.authError.passwordAttemptsExceeded".localized()
204+
default:
205+
return "authenticator.authError.incorrectCredentials".localized()
206+
}
202207
}
203208

204209
if case .validation(let field, _, _, _) = error {

Tests/AuthenticatorTests/States/AuthenticatorBaseStateTests.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,14 @@ class AuthenticatorBaseStateTests: XCTestCase {
221221
XCTAssertEqual(authenticatorError.content, "authenticator.unknownError".localized())
222222
}
223223

224-
func testError_withNotAuthorizedError_shouldReturnLocalizedError() {
225-
let authenticatorError = state.error(for: AuthError.notAuthorized("description", "recovery", nil))
224+
func testError_withNotAuthorizedError_withPasswordAttemptsExceededDescription_shouldReturnLocalizedError() {
225+
let authenticatorError = state.error(for: AuthError.notAuthorized("Password attempts exceeded", "recovery", nil))
226+
XCTAssertEqual(authenticatorError.style, .error)
227+
XCTAssertEqual(authenticatorError.content, "authenticator.authError.passwordAttemptsExceeded".localized())
228+
}
229+
230+
func testError_withNotAuthorizedError_withAnotherDescription_shouldReturnLocalizedError() {
231+
let authenticatorError = state.error(for: AuthError.notAuthorized("Unable to sign in", "recovery", nil))
226232
XCTAssertEqual(authenticatorError.style, .error)
227233
XCTAssertEqual(authenticatorError.content, "authenticator.authError.incorrectCredentials".localized())
228234
}

0 commit comments

Comments
 (0)