Skip to content

Commit

Permalink
fix: Fixing issues with Sign Up fields (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaland authored Jun 14, 2023
1 parent ad89356 commit f96d96f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/Authenticator/Constants/ComponentInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import Foundation

public class ComponentInformation {
public static let version = "1.0.0-dev-preview"
public static let version = "1.0.1"
public static let name = "amplify-ui-swift-authenticator"
}
28 changes: 27 additions & 1 deletion Sources/Authenticator/States/SignUpState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ public class SignUpState: AuthenticatorBaseState {

setBusy(true)
let cognitoConfiguration = authenticatorState.configuration
var inputs = signUpFields.map { Field(field: $0) }

var existingFields: Set<String> = []
var inputs = signUpFields.compactMap { field -> Field? in
guard !existingFields.contains(field.rawValue) else {
log.warn("Skipping configuring field of type '\(field.rawValue)' because it was already present.")
return nil
}

existingFields.insert(field.rawValue)
return Field(field: field)
}

for attribute in cognitoConfiguration.verificationMechanisms {
if let index = inputs.firstIndex(where: { $0.field.attributeType == attribute.asSignUpAttribute }) {
if !inputs[index].field.isRequired {
Expand Down Expand Up @@ -160,3 +171,18 @@ public extension SignUpState {
}
}
}

private extension SignUpField {
var rawValue: String {
switch attributeType {
case .username:
return "username"
case .password:
return "password"
case .passwordConfirmation:
return "passwordConfirmation"
default:
return attributeType.attributeKey?.rawValue ?? "unknown"
}
}
}
6 changes: 4 additions & 2 deletions Sources/Authenticator/Views/Primitives/PhoneNumberField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ struct PhoneNumberField: View {
CallingCodeField(callingCode: $callingCode)
.foregroundColor(foregroundColor)
.focused($focusedField, equals: .callingCode)
.onChange(of: callingCode) { text in
self.text = "\(text)\(phoneNumber)"
.onChange(of: callingCode) { code in
if !phoneNumber.isEmpty {
text = "\(code)\(phoneNumber)"
}
}

Divider()
Expand Down

0 comments on commit f96d96f

Please sign in to comment.