Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Authenticator): Adding new error localizations for limits exceeded #96

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@

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

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

/* Toolbar displayed on top of the keyboard */
"authenticator.keyboardToolbar.Done" = "Done";
9 changes: 7 additions & 2 deletions Sources/Authenticator/States/AuthenticatorBaseState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ public class AuthenticatorBaseState: ObservableObject {
}

private func localizedMessage(for error: AuthError) -> String? {
if case .notAuthorized(_, _, _) = error {
return "authenticator.authError.incorrectCredentials".localized()
if case .notAuthorized(let description, _, _) = error {
switch description {
case "Password attempts exceeded":
return "authenticator.authError.passwordAttemptsExceeded".localized()
default:
return "authenticator.authError.incorrectCredentials".localized()
}
}

if case .validation(let field, _, _, _) = error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,14 @@ class AuthenticatorBaseStateTests: XCTestCase {
XCTAssertEqual(authenticatorError.content, "authenticator.unknownError".localized())
}

func testError_withNotAuthorizedError_shouldReturnLocalizedError() {
let authenticatorError = state.error(for: AuthError.notAuthorized("description", "recovery", nil))
func testError_withNotAuthorizedError_withPasswordAttemptsExceededDescription_shouldReturnLocalizedError() {
let authenticatorError = state.error(for: AuthError.notAuthorized("Password attempts exceeded", "recovery", nil))
XCTAssertEqual(authenticatorError.style, .error)
XCTAssertEqual(authenticatorError.content, "authenticator.authError.passwordAttemptsExceeded".localized())
}

func testError_withNotAuthorizedError_withAnotherDescription_shouldReturnLocalizedError() {
let authenticatorError = state.error(for: AuthError.notAuthorized("Unable to sign in", "recovery", nil))
XCTAssertEqual(authenticatorError.style, .error)
XCTAssertEqual(authenticatorError.content, "authenticator.authError.incorrectCredentials".localized())
}
Expand Down
Loading