Skip to content

Commit 1b7d17a

Browse files
committed
fix: remove setVerificationCode for phone auth
1 parent c4bd5fc commit 1b7d17a

11 files changed

Lines changed: 89 additions & 81 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthConfiguration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct AuthConfiguration {
2222
public let interactiveDismissEnabled: Bool
2323
public let shouldAutoUpgradeAnonymousUsers: Bool
2424
public let customStringsBundle: Bundle?
25-
public let locale: Locale?
25+
public let languageCode: String?
2626
public let tosUrl: URL?
2727
public let privacyPolicyUrl: URL?
2828
public let emailLinkSignInActionCodeSettings: ActionCodeSettings?
@@ -40,7 +40,7 @@ public struct AuthConfiguration {
4040
interactiveDismissEnabled: Bool = true,
4141
shouldAutoUpgradeAnonymousUsers: Bool = false,
4242
customStringsBundle: Bundle? = nil,
43-
locale: Locale? = nil,
43+
languageCode: String? = nil,
4444
tosUrl: URL? = nil,
4545
privacyPolicyUrl: URL? = nil,
4646
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,
@@ -54,7 +54,7 @@ public struct AuthConfiguration {
5454
self.interactiveDismissEnabled = interactiveDismissEnabled
5555
self.shouldAutoUpgradeAnonymousUsers = shouldAutoUpgradeAnonymousUsers
5656
self.customStringsBundle = customStringsBundle
57-
self.locale = locale
57+
self.languageCode = languageCode
5858
self.tosUrl = tosUrl
5959
self.privacyPolicyUrl = privacyPolicyUrl
6060
self.emailLinkSignInActionCodeSettings = emailLinkSignInActionCodeSettings

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public protocol AuthProviderUI {
2929

3030
public protocol PhoneAuthProviderSwift: AuthProviderSwift {
3131
@MainActor func verifyPhoneNumber(phoneNumber: String) async throws -> String
32-
func setVerificationCode(verificationID: String, code: String)
32+
@MainActor func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential
3333
}
3434

3535
public enum AuthenticationState {
@@ -109,7 +109,7 @@ public final class AuthService {
109109
public init(configuration: AuthConfiguration = AuthConfiguration(), auth: Auth = Auth.auth()) {
110110
self.auth = auth
111111
self.configuration = configuration
112-
string = StringUtils(bundle: configuration.customStringsBundle ?? Bundle.module, locale: configuration.locale)
112+
string = StringUtils(bundle: configuration.customStringsBundle ?? Bundle.module, languageCode: configuration.languageCode)
113113
listenerManager = AuthListenerManager(auth: auth, authEnvironment: self)
114114
FirebaseApp.registerLibrary("firebase-ui-ios", withVersion: FirebaseAuthSwiftUIVersion.version)
115115
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Utils/StringUtils.swift

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,22 @@ let kKeyNotFound = "Key not found"
1919

2020
public class StringUtils {
2121
let bundle: Bundle
22-
let locale: Locale?
22+
let languageCode: String?
2323

24-
init(bundle: Bundle, locale: Locale? = nil) {
24+
init(bundle: Bundle, languageCode: String? = nil) {
2525
self.bundle = bundle
26-
self.locale = locale
26+
self.languageCode = languageCode
2727
}
2828

2929
public func localizedString(for key: String) -> String {
30-
// If a specific locale is set, use NSLocalizedString with the locale's language code
31-
if let locale {
32-
let languageCode = locale.language.languageCode?.identifier ?? locale.identifier
33-
34-
// Get the localized string from the bundle for the specific language
35-
if let path = bundle.path(forResource: languageCode, ofType: "lproj"),
36-
let localizedBundle = Bundle(path: path) {
37-
let localizedString = localizedBundle.localizedString(forKey: key, value: nil, table: "Localizable")
38-
// If we got a localized string (not the key back), return it
39-
if localizedString != key {
40-
return localizedString
41-
}
42-
}
43-
44-
// Fallback to default bundle if language-specific bundle not found
45-
return bundle.localizedString(forKey: key, value: nil, table: "Localizable")
46-
} else {
47-
let keyLocale = String.LocalizationValue(key)
48-
let value = String(localized: keyLocale, bundle: bundle)
49-
return value
30+
// 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) {
32+
return localizedBundle.localizedString(forKey: key, value: nil, table: "Localizable")
5033
}
34+
35+
// Use default localization
36+
let keyLocale = String.LocalizationValue(key)
37+
return String(localized: keyLocale, bundle: bundle)
5138
}
5239

5340
public func localizedErrorMessage(for error: Error) -> String {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterPhoneNumberView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ struct EnterPhoneNumberView: View {
9999
return "mock-verification-id"
100100
}
101101

102-
func setVerificationCode(verificationID _: String, code _: String) {
103-
// Mock implementation
104-
}
105-
106102
func createAuthCredential() async throws -> AuthCredential {
107103
fatalError("Not implemented in preview")
108104
}
105+
106+
func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential {
107+
fatalError("Not implemented in preview")
108+
}
109109
}
110110

111111
return EnterPhoneNumberView(phoneProvider: MockPhoneProvider())

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterVerificationCodeView.swift

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ import SwiftUI
2020
@MainActor
2121
struct EnterVerificationCodeView: View {
2222
@Environment(AuthService.self) private var authService
23-
@Environment(\.dismiss) private var dismiss
2423
@State private var verificationCode: String = ""
25-
@State private var currentError: AlertError? = nil
26-
@State private var isProcessing: Bool = false
2724

2825
let verificationID: String
2926
let fullPhoneNumber: String
3027
let phoneProvider: PhoneAuthProviderSwift
3128

3229
var body: some View {
30+
@Bindable var authService = authService
3331
VStack(spacing: 32) {
3432
VStack(spacing: 16) {
3533
VStack(spacing: 8) {
@@ -50,31 +48,21 @@ struct EnterVerificationCodeView: View {
5048
.padding(.bottom)
5149
.frame(maxWidth: .infinity, alignment: .leading)
5250

53-
VerificationCodeInputField(
54-
code: $verificationCode,
55-
isError: currentError != nil,
56-
errorMessage: currentError?.message
57-
)
51+
VerificationCodeInputField(code: $verificationCode)
5852

5953
Button(action: {
6054
Task {
61-
isProcessing = true
6255
do {
63-
phoneProvider.setVerificationCode(
64-
verificationID: verificationID,
65-
code: verificationCode
66-
)
67-
let credential = try await phoneProvider.createAuthCredential()
56+
let credential = try await phoneProvider.createAuthCredential(verificationId: verificationID, verificationCode: verificationCode)
6857

6958
_ = try await authService.signIn(credentials: credential)
70-
dismiss()
59+
authService.navigator.clear()
7160
} catch {
72-
currentError = AlertError(message: error.localizedDescription)
73-
isProcessing = false
61+
7462
}
7563
}
7664
}) {
77-
if isProcessing {
65+
if authService.authenticationState == .authenticating {
7866
ProgressView()
7967
.frame(height: 32)
8068
.frame(maxWidth: .infinity)
@@ -85,15 +73,15 @@ struct EnterVerificationCodeView: View {
8573
}
8674
}
8775
.buttonStyle(.borderedProminent)
88-
.disabled(isProcessing || verificationCode.count != 6)
76+
.disabled(authService.authenticationState == .authenticating || verificationCode.count != 6)
8977
}
9078

9179
Spacer()
9280
}
9381
.navigationTitle(authService.string.enterVerificationCodeTitle)
9482
.navigationBarTitleDisplayMode(.inline)
9583
.padding(.horizontal)
96-
.errorAlert(error: $currentError, okButtonLabel: authService.string.okButtonLabel)
84+
.errorAlert(error: $authService.currentError, okButtonLabel: authService.string.okButtonLabel)
9785
}
9886
}
9987

@@ -107,13 +95,13 @@ struct EnterVerificationCodeView: View {
10795
return "mock-verification-id"
10896
}
10997

110-
func setVerificationCode(verificationID _: String, code _: String) {
111-
// Mock implementation
112-
}
113-
11498
func createAuthCredential() async throws -> AuthCredential {
11599
fatalError("Not implemented in preview")
116100
}
101+
102+
func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential {
103+
fatalError("Not implemented in preview")
104+
}
117105
}
118106

119107
return NavigationStack {

FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources/Services/PhoneAuthProviderAuthUI.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import SwiftUI
1919
public typealias VerificationID = String
2020

2121
public class PhoneProviderSwift: PhoneAuthProviderSwift {
22-
private var verificationID: String?
23-
private var verificationCode: String?
24-
2522
public init() {}
2623

2724
@MainActor public func verifyPhoneNumber(phoneNumber: String) async throws -> VerificationID {
@@ -37,19 +34,13 @@ public class PhoneProviderSwift: PhoneAuthProviderSwift {
3734
}
3835
}
3936

40-
public func setVerificationCode(verificationID: String, code: String) {
41-
self.verificationID = verificationID
42-
verificationCode = code
43-
}
44-
4537
@MainActor public func createAuthCredential() async throws -> AuthCredential {
46-
guard let verificationID = verificationID,
47-
let verificationCode = verificationCode else {
48-
throw AuthServiceError.providerAuthenticationFailed("Verification ID or code not set")
49-
}
50-
38+
fatalError("Not implemented")
39+
}
40+
41+
@MainActor public func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential {
5142
return PhoneAuthProvider.provider()
52-
.credential(withVerificationID: verificationID, verificationCode: verificationCode)
43+
.credential(withVerificationID: verificationId, verificationCode: verificationCode)
5344
}
5445
}
5546

firebase-debug.log

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[debug] [2025-11-05T12:00:41.564Z] ----------------------------------------------------------------------
2+
[debug] [2025-11-05T12:00:41.565Z] Command: /opt/homebrew/Cellar/node/25.1.0_1/bin/node /Users/ademolafadumo/.npm-global/bin/firebase emulators:start --only auth
3+
[debug] [2025-11-05T12:00:41.565Z] CLI Version: 14.23.0
4+
[debug] [2025-11-05T12:00:41.565Z] Platform: darwin
5+
[debug] [2025-11-05T12:00:41.565Z] Node Version: v25.1.0
6+
[debug] [2025-11-05T12:00:41.566Z] Time: Wed Nov 05 2025 13:00:41 GMT+0100 (West Africa Standard Time)
7+
[debug] [2025-11-05T12:00:41.566Z] ----------------------------------------------------------------------
8+
[debug]
9+
[debug] [2025-11-05T12:00:41.581Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
10+
[debug] [2025-11-05T12:00:41.581Z] > authorizing via signed-in user (demolafadumo@gmail.com)
11+
[warn] ⚠ Could not find config (firebase.json) so using defaults.
12+
[info] i emulators: Starting emulators: auth {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: auth"}}
13+
[info] i emulators: Detected demo project ID "demo-no-project", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail. {"metadata":{"emulator":{"name":"hub"},"message":"Detected demo project ID \"demo-no-project\", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail."}}
14+
[debug] [2025-11-05T12:00:41.851Z] [logging] Logging Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
15+
[debug] [2025-11-05T12:00:41.851Z] [auth] Authentication Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
16+
[debug] [2025-11-05T12:00:41.851Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400},{"address":"::1","family":"IPv6","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000},{"address":"::1","family":"IPv6","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"auth":[{"address":"127.0.0.1","family":"IPv4","port":9099}]},"metadata":{"message":"assigned listening specs for emulators"}}
17+
[debug] [2025-11-05T12:00:41.854Z] Emulator locator file path: /var/folders/pw/cv4hgr3x2fbcrxbj9s2d60dw0000gn/T/hub-demo-no-project.json
18+
[debug] [2025-11-05T12:00:41.854Z] [hub] writing locator at /var/folders/pw/cv4hgr3x2fbcrxbj9s2d60dw0000gn/T/hub-demo-no-project.json
19+
[debug] [2025-11-05T12:00:44.618Z] Could not find VSCode notification endpoint: FetchError: request to http://localhost:40001/vscode/notify failed, reason: . If you are not running the Firebase Data Connect VSCode extension, this is expected and not an issue.
20+
[info]
21+
┌─────────────────────────────────────────────────────────────┐
22+
│ ✔ All emulators ready! It is now safe to connect your app. │
23+
│ i View Emulator UI at http://127.0.0.1:4000/ │
24+
└─────────────────────────────────────────────────────────────┘
25+
26+
┌────────────────┬────────────────┬────────────────────────────┐
27+
│ Emulator │ Host:Port │ View in Emulator UI │
28+
├────────────────┼────────────────┼────────────────────────────┤
29+
│ Authentication │ 127.0.0.1:9099 │ http://127.0.0.1:4000/auth │
30+
└────────────────┴────────────────┴────────────────────────────┘
31+
Emulator Hub host: 127.0.0.1 port: 4400
32+
Other reserved ports: 4500
33+
34+
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
35+
36+
[info] i To verify the phone number +2348145495544, use the code 544557. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 544557."}}
37+
[info] i To verify the phone number +2348145495544, use the code 227440. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 227440."}}
38+
[info] i To verify the phone number +2348145495544, use the code 777655. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 777655."}}
39+
[info] i To verify the phone number +2348145495544, use the code 309002. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 309002."}}
40+
[info] i To verify the phone number +2348145495544, use the code 227291. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 227291."}}
41+
[info] i To verify the phone number +2348145495544, use the code 419134. {"metadata":{"emulator":{"name":"auth"},"message":"To verify the phone number +2348145495544, use the code 419134."}}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample.xcodeproj/xcshareddata/xcschemes/FirebaseSwiftUIExample.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
shouldAutocreateTestPlan = "YES">
3232
</TestAction>
3333
<LaunchAction
34-
buildConfiguration = "Release"
34+
buildConfiguration = "Debug"
3535
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3636
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
3737
launchStyle = "0"

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/App/ContentView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ struct ContentView: View {
3939
actionCodeSettings.linkDomain = "flutterfire-e2e-tests.firebaseapp.com"
4040
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
4141
let configuration = AuthConfiguration(
42-
locale: Locale(identifier: "es"),
42+
languageCode: "es",
4343
tosUrl: URL(string: "https://example.com/tos"),
4444
privacyPolicyUrl: URL(string: "https://example.com/privacy"),
4545
emailLinkSignInActionCodeSettings: actionCodeSettings,
46-
mfaEnabled: true
46+
mfaEnabled: false
4747
)
4848

4949
authService = AuthService(
@@ -67,6 +67,8 @@ struct ContentView: View {
6767
)
6868
)
6969
.withEmailSignIn()
70+
71+
authService.auth.useEmulator(withHost: "127.0.0.1", port: 9099)
7072
}
7173

7274
let authService: AuthService

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/App/FirebaseSwiftUIExampleApp.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct FirebaseSwiftUIExampleApp: App {
7979

8080
var body: some Scene {
8181
WindowGroup {
82-
// ContentViewSheetExample()
8382
if testRunner {
8483
TestView()
8584
} else {

0 commit comments

Comments
 (0)