Skip to content

Commit 29840d4

Browse files
Merge pull request #1295 from firebase/format
2 parents 080b27a + db585b1 commit 29840d4

File tree

9 files changed

+80
-63
lines changed

9 files changed

+80
-63
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthConfiguration.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,19 @@ public struct AuthConfiguration {
3434
public let allowedSecondFactors: Set<SecondFactorType>
3535
public let mfaIssuer: String
3636

37-
public init(
38-
logo: ImageResource? = nil,
39-
languageCode: String? = nil,
40-
shouldHideCancelButton: Bool = false,
41-
interactiveDismissEnabled: Bool = true,
42-
shouldAutoUpgradeAnonymousUsers: Bool = false,
43-
customStringsBundle: Bundle? = nil,
44-
tosUrl: URL? = nil,
45-
privacyPolicyUrl: URL? = nil,
46-
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,
47-
verifyEmailActionCodeSettings: ActionCodeSettings? = nil,
48-
mfaEnabled: Bool = false,
49-
allowedSecondFactors: Set<SecondFactorType> = [.sms, .totp],
50-
mfaIssuer: String = "Firebase Auth"
51-
) {
37+
public init(logo: ImageResource? = nil,
38+
languageCode: String? = nil,
39+
shouldHideCancelButton: Bool = false,
40+
interactiveDismissEnabled: Bool = true,
41+
shouldAutoUpgradeAnonymousUsers: Bool = false,
42+
customStringsBundle: Bundle? = nil,
43+
tosUrl: URL? = nil,
44+
privacyPolicyUrl: URL? = nil,
45+
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,
46+
verifyEmailActionCodeSettings: ActionCodeSettings? = nil,
47+
mfaEnabled: Bool = false,
48+
allowedSecondFactors: Set<SecondFactorType> = [.sms, .totp],
49+
mfaIssuer: String = "Firebase Auth") {
5250
self.logo = logo
5351
self.shouldHideCancelButton = shouldHideCancelButton
5452
self.interactiveDismissEnabled = interactiveDismissEnabled

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Utils/StringUtils.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class StringUtils {
2828

2929
public func localizedString(for key: String) -> String {
3030
// If a specific language code is set, load strings from that language bundle
31-
if let languageCode, let path = bundle.path(forResource: languageCode, ofType: "lproj"), let localizedBundle = Bundle(path: path) {
31+
if let languageCode, let path = bundle.path(forResource: languageCode, ofType: "lproj"),
32+
let localizedBundle = Bundle(path: path) {
3233
return localizedBundle.localizedString(forKey: key, value: nil, table: "Localizable")
3334
}
3435

@@ -605,14 +606,18 @@ public class StringUtils {
605606
/// found in:
606607
/// - MFAEnrolmentView
607608
public var authenticatorAppInstructionsMessage: String {
608-
return localizedString(for: "Use an authenticator app like Google Authenticator or Authy to generate verification codes.")
609+
return localizedString(
610+
for: "Use an authenticator app like Google Authenticator or Authy to generate verification codes."
611+
)
609612
}
610613

611614
/// Set up two-factor authentication to add an extra layer of security to your account.
612615
/// found in:
613616
/// - MFAEnrolmentView
614617
public var setUpTwoFactorAuthMessage: String {
615-
return localizedString(for: "Set up two-factor authentication to add an extra layer of security to your account.")
618+
return localizedString(
619+
for: "Set up two-factor authentication to add an extra layer of security to your account."
620+
)
616621
}
617622

618623
/// We'll send a verification code to this number
@@ -633,7 +638,9 @@ public class StringUtils {
633638
/// found in:
634639
/// - MFAEnrolmentView
635640
public var sendVerificationCodeEachSignInMessage: String {
636-
return localizedString(for: "We'll send a verification code to your phone number each time you sign in.")
641+
return localizedString(
642+
for: "We'll send a verification code to your phone number each time you sign in."
643+
)
637644
}
638645

639646
/// Unable to generate QR Code
@@ -663,7 +670,9 @@ public class StringUtils {
663670
/// - MFAEnrolmentView
664671
/// - MFAResolutionView
665672
public var mfaNotEnabledMessage: String {
666-
return localizedString(for: "MFA is not enabled in the current configuration. Please contact your administrator.")
673+
return localizedString(
674+
for: "MFA is not enabled in the current configuration. Please contact your administrator."
675+
)
667676
}
668677

669678
/// No Authentication Methods Available
@@ -679,7 +688,9 @@ public class StringUtils {
679688
/// - MFAEnrolmentView
680689
/// - MFAResolutionView
681690
public var noMFAMethodsConfiguredMessage: String {
682-
return localizedString(for: "No MFA methods are configured as allowed. Please contact your administrator.")
691+
return localizedString(
692+
for: "No MFA methods are configured as allowed. Please contact your administrator."
693+
)
683694
}
684695

685696
/// Complete sign-in with your second factor
@@ -823,11 +834,14 @@ public class StringUtils {
823834
return localizedString(for: "Delete Account?")
824835
}
825836

826-
/// This action cannot be undone. All your data will be permanently deleted. You may need to reauthenticate to complete this action.
837+
/// This action cannot be undone. All your data will be permanently deleted. You may need to
838+
/// reauthenticate to complete this action.
827839
/// found in:
828840
/// - SignedInView
829841
public var deleteAccountWarningMessage: String {
830-
return localizedString(for: "This action cannot be undone. All your data will be permanently deleted. You may need to reauthenticate to complete this action.")
842+
return localizedString(
843+
for: "This action cannot be undone. All your data will be permanently deleted. You may need to reauthenticate to complete this action."
844+
)
831845
}
832846

833847
/// Invalid OAuth Provider error

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct AuthPickerView<Content: View> {
2222
public init(@ViewBuilder content: @escaping () -> Content = { EmptyView() }) {
2323
self.content = content
2424
}
25-
25+
2626
@Environment(AuthService.self) private var authService
2727
private let content: () -> Content
2828

@@ -61,7 +61,10 @@ extension AuthPickerView: View {
6161
case AuthView.enterPhoneNumber:
6262
EnterPhoneNumberView()
6363
case let .enterVerificationCode(verificationID, fullPhoneNumber):
64-
EnterVerificationCodeView(verificationID: verificationID, fullPhoneNumber: fullPhoneNumber)
64+
EnterVerificationCodeView(
65+
verificationID: verificationID,
66+
fullPhoneNumber: fullPhoneNumber
67+
)
6568
}
6669
}
6770
}
@@ -123,7 +126,7 @@ extension AuthPickerView: View {
123126
}
124127
}
125128
}
126-
129+
127130
@ToolbarContentBuilder
128131
var toolbar: some ToolbarContent {
129132
ToolbarItem(placement: .topBarTrailing) {
@@ -137,7 +140,7 @@ extension AuthPickerView: View {
137140
}
138141
}
139142
}
140-
143+
141144
@ViewBuilder
142145
var authPickerViewInternal: some View {
143146
@Bindable var authService = authService
@@ -167,7 +170,7 @@ extension AuthPickerView: View {
167170
okButtonLabel: authService.string.okButtonLabel
168171
)
169172
}
170-
173+
171174
@ViewBuilder
172175
var authMethodPicker: some View {
173176
GeometryReader { proxy in
@@ -187,7 +190,7 @@ extension AuthPickerView: View {
187190
}
188191
}
189192
}
190-
193+
191194
@ViewBuilder
192195
func otherSignInOptions(_ proxy: GeometryProxy) -> some View {
193196
VStack {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailAuthView.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ private enum FocusableField: Hashable {
3232
@MainActor
3333
public struct EmailAuthView {
3434
@Environment(AuthService.self) private var authService
35-
35+
3636
@State private var email = ""
3737
@State private var password = ""
3838
@State private var confirmPassword = ""
39-
39+
4040
@FocusState private var focus: FocusableField?
41-
41+
4242
public init() {}
43-
43+
4444
private var isValid: Bool {
4545
return if authService.authenticationFlow == .signIn {
4646
!email.isEmpty && !password.isEmpty
4747
} else {
4848
!email.isEmpty && !password.isEmpty && password == confirmPassword
4949
}
5050
}
51-
51+
5252
private func signInWithEmailPassword() async {
5353
try? await authService.signIn(email: email, password: password)
5454
}
55-
55+
5656
private func createUserWithEmailPassword() async {
5757
try? await authService.createUser(email: email, password: password)
5858
}
@@ -101,7 +101,7 @@ extension EmailAuthView: View {
101101
}
102102
.accessibilityIdentifier("password-recovery-button")
103103
}
104-
104+
105105
if authService.authenticationFlow == .signUp {
106106
AuthTextField(
107107
text: $confirmPassword,
@@ -120,7 +120,7 @@ extension EmailAuthView: View {
120120
.focused($focus, equals: .confirmPassword)
121121
.accessibilityIdentifier("confirm-password-field")
122122
}
123-
123+
124124
Button(action: {
125125
Task {
126126
if authService.authenticationFlow == .signIn {
@@ -133,8 +133,8 @@ extension EmailAuthView: View {
133133
if authService.authenticationState != .authenticating {
134134
Text(
135135
authService.authenticationFlow == .signIn
136-
? authService.string.signInWithEmailButtonLabel
137-
: authService.string.signUpWithEmailButtonLabel
136+
? authService.string.signInWithEmailButtonLabel
137+
: authService.string.signUpWithEmailButtonLabel
138138
)
139139
.padding(.vertical, 8)
140140
.frame(maxWidth: .infinity)
@@ -154,22 +154,22 @@ extension EmailAuthView: View {
154154
Button(action: {
155155
withAnimation {
156156
authService.authenticationFlow =
157-
authService
158-
.authenticationFlow == .signIn ? .signUp : .signIn
157+
authService
158+
.authenticationFlow == .signIn ? .signUp : .signIn
159159
}
160160
}) {
161161
HStack(spacing: 4) {
162162
Text(
163163
authService
164164
.authenticationFlow == .signIn
165-
? authService.string.dontHaveAnAccountYetLabel
166-
: authService.string.alreadyHaveAnAccountLabel
165+
? authService.string.dontHaveAnAccountYetLabel
166+
: authService.string.alreadyHaveAnAccountLabel
167167
)
168168
.foregroundStyle(Color(.label))
169169
Text(
170170
authService.authenticationFlow == .signUp
171-
? authService.string.emailLoginFlowLabel
172-
: authService.string.emailSignUpFlowLabel
171+
? authService.string.emailLoginFlowLabel
172+
: authService.string.emailSignUpFlowLabel
173173
)
174174
.fontWeight(.semibold)
175175
.foregroundColor(.blue)

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterPhoneNumberView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ struct EnterPhoneNumberView: View {
5757
verificationID: id,
5858
fullPhoneNumber: fullPhoneNumber
5959
))
60-
} catch {
61-
}
60+
} catch {}
6261
}
6362
}) {
6463
if authService.authenticationState == .authenticating {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterVerificationCodeView.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ struct EnterVerificationCodeView: View {
5555
guard let provider = authService.currentPhoneProvider else {
5656
fatalError("No phone provider found")
5757
}
58-
let credential = try await provider.createAuthCredential(verificationId: verificationID, verificationCode: verificationCode)
58+
let credential = try await provider.createAuthCredential(
59+
verificationId: verificationID,
60+
verificationCode: verificationCode
61+
)
5962

6063
_ = try await authService.signIn(credentials: credential)
6164
authService.navigator.clear()
62-
} catch {
63-
64-
}
65+
} catch {}
6566
}
6667
}) {
6768
if authService.authenticationState == .authenticating {

FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources/Services/PhoneAuthProviderAuthUI.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ public class PhoneProviderSwift: PhoneAuthProviderSwift {
3737
@MainActor public func createAuthCredential() async throws -> AuthCredential {
3838
fatalError("Not implemented")
3939
}
40-
41-
@MainActor public func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential {
40+
41+
@MainActor public func createAuthCredential(verificationId: String,
42+
verificationCode: String) async throws
43+
-> AuthCredential {
4244
return PhoneAuthProvider.provider()
4345
.credential(withVerificationID: verificationId, verificationCode: verificationCode)
4446
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/TestUtils.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func createEmail() -> String {
3333

3434
/// Helper to create a test user in the emulator via REST API (avoids keychain issues)
3535
@MainActor func createTestUser(email: String, password: String = "123456",
36-
verifyEmail: Bool = false) async throws {
36+
verifyEmail: Bool = false) async throws {
3737
// Use Firebase Auth emulator REST API directly to avoid keychain access issues in UI tests
3838
let signUpUrl =
3939
"http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signUp?key=fake-api-key"
@@ -78,9 +78,9 @@ func createEmail() -> String {
7878

7979
/// Verifies an email address in the emulator using the OOB code mechanism
8080
@MainActor func verifyEmailInEmulator(email: String,
81-
idToken: String,
82-
projectID: String = "flutterfire-e2e-tests",
83-
emulatorHost: String = "127.0.0.1:9099") async throws {
81+
idToken: String,
82+
projectID: String = "flutterfire-e2e-tests",
83+
emulatorHost: String = "127.0.0.1:9099") async throws {
8484
let base = "http://\(emulatorHost)"
8585

8686
// Step 1: Trigger email verification (creates OOB code in emulator)

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/UpgradeAccountUITests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ final class UpgradeAccountUITests: XCTestCase {
3434
let email = createEmail()
3535
let password = "123456"
3636
try await createTestUser(email: email, password: password)
37-
37+
3838
// Launch app with anonymous sign-in enabled
3939
let app = createTestApp()
4040
app.launchArguments.append("--anonymous-sign-in-enabled")
4141
app.launch()
42-
42+
4343
// Wait for sign-in screen to appear
4444
let emailField = app.textFields["email-field"]
4545
XCTAssertTrue(emailField.waitForExistence(timeout: 6), "Email field should exist")
4646
emailField.tap()
4747
emailField.typeText(email)
48-
48+
4949
let passwordField = app.secureTextFields["password-field"]
5050
XCTAssertTrue(passwordField.exists, "Password field should exist")
5151
passwordField.tap()
5252
passwordField.typeText(password)
53-
53+
5454
let signInButton = app.buttons["sign-in-button"]
5555
XCTAssertTrue(signInButton.exists, "Sign-In button should exist")
5656
signInButton.tap()
57-
57+
5858
let signedInText = app.staticTexts["signed-in-text"]
59-
59+
6060
// Wait for authentication to complete and signed-in view to appear
6161
XCTAssertTrue(
6262
signedInText.waitForExistence(timeout: 30),

0 commit comments

Comments
 (0)