Skip to content

Commit f96d96f

Browse files
authored
fix: Fixing issues with Sign Up fields (#25)
1 parent ad89356 commit f96d96f

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

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.0.0-dev-preview"
11+
public static let version = "1.0.1"
1212
public static let name = "amplify-ui-swift-authenticator"
1313
}

Sources/Authenticator/States/SignUpState.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,18 @@ public class SignUpState: AuthenticatorBaseState {
8989

9090
setBusy(true)
9191
let cognitoConfiguration = authenticatorState.configuration
92-
var inputs = signUpFields.map { Field(field: $0) }
92+
93+
var existingFields: Set<String> = []
94+
var inputs = signUpFields.compactMap { field -> Field? in
95+
guard !existingFields.contains(field.rawValue) else {
96+
log.warn("Skipping configuring field of type '\(field.rawValue)' because it was already present.")
97+
return nil
98+
}
99+
100+
existingFields.insert(field.rawValue)
101+
return Field(field: field)
102+
}
103+
93104
for attribute in cognitoConfiguration.verificationMechanisms {
94105
if let index = inputs.firstIndex(where: { $0.field.attributeType == attribute.asSignUpAttribute }) {
95106
if !inputs[index].field.isRequired {
@@ -160,3 +171,18 @@ public extension SignUpState {
160171
}
161172
}
162173
}
174+
175+
private extension SignUpField {
176+
var rawValue: String {
177+
switch attributeType {
178+
case .username:
179+
return "username"
180+
case .password:
181+
return "password"
182+
case .passwordConfirmation:
183+
return "passwordConfirmation"
184+
default:
185+
return attributeType.attributeKey?.rawValue ?? "unknown"
186+
}
187+
}
188+
}

Sources/Authenticator/Views/Primitives/PhoneNumberField.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ struct PhoneNumberField: View {
5959
CallingCodeField(callingCode: $callingCode)
6060
.foregroundColor(foregroundColor)
6161
.focused($focusedField, equals: .callingCode)
62-
.onChange(of: callingCode) { text in
63-
self.text = "\(text)\(phoneNumber)"
62+
.onChange(of: callingCode) { code in
63+
if !phoneNumber.isEmpty {
64+
text = "\(code)\(phoneNumber)"
65+
}
6466
}
6567

6668
Divider()

0 commit comments

Comments
 (0)