Skip to content

Commit f7c6f90

Browse files
update the sample app to use link domains for ActionCodeSettings (#13498)
1 parent 80e7e36 commit f7c6f90

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Models/AuthMenu.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum AuthMenu: String {
4343
case deleteApp
4444
case actionType
4545
case continueURL
46+
case linkDomain
4647
case requestVerifyEmail
4748
case requestPasswordReset
4849
case resetPassword
@@ -117,6 +118,8 @@ enum AuthMenu: String {
117118
return "Action Type"
118119
case .continueURL:
119120
return "Continue URL"
121+
case .linkDomain:
122+
return "Link Domain"
120123
case .requestVerifyEmail:
121124
return "Request Verify Email"
122125
case .requestPasswordReset:
@@ -197,6 +200,8 @@ enum AuthMenu: String {
197200
self = .actionType
198201
case "Continue URL":
199202
self = .continueURL
203+
case "Link Domain":
204+
self = .linkDomain
200205
case "Request Verify Email":
201206
self = .requestVerifyEmail
202207
case "Request Password Reset":
@@ -328,6 +333,7 @@ class AuthMenuData: DataSourceProvidable {
328333
let items: [Item] = [
329334
Item(title: AuthMenu.actionType.name, detailTitle: ActionCodeRequestType.inApp.name),
330335
Item(title: AuthMenu.continueURL.name, detailTitle: "--", isEditable: true),
336+
Item(title: AuthMenu.linkDomain.name, detailTitle: "--", isEditable: true),
331337
Item(title: AuthMenu.requestVerifyEmail.name),
332338
Item(title: AuthMenu.requestPasswordReset.name),
333339
Item(title: AuthMenu.resetPassword.name),

FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AccountLinkingViewController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ class AccountLinkingViewController: UIViewController, DataSourceProviderDelegate
317317
/// Similar to in `PasswordlessViewController`, enter the authorized domain.
318318
/// Please refer to this Quickstart's README for more information.
319319
private let authorizedDomain: String = "ENTER AUTHORIZED DOMAIN"
320+
321+
/// This is the replacement for customized dynamic link domain.
322+
private let customDomain: String = "ENTER AUTHORIZED HOSTING DOMAIN"
320323
/// Maintain a reference to the email entered for linking user to Passwordless.
321324
private var email: String?
322325

@@ -343,6 +346,7 @@ class AccountLinkingViewController: UIViewController, DataSourceProviderDelegate
343346
// The sign-in operation must be completed in the app.
344347
actionCodeSettings.handleCodeInApp = true
345348
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
349+
actionCodeSettings.linkDomain = customDomain
346350

347351
AppManager.shared.auth()
348352
.sendSignInLink(toEmail: email, actionCodeSettings: actionCodeSettings) { error in

FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/AuthViewController.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
3939
var authStateDidChangeListeners: [AuthStateDidChangeListenerHandle] = []
4040
var IDTokenDidChangeListeners: [IDTokenDidChangeListenerHandle] = []
4141
var actionCodeContinueURL: URL?
42+
var actionCodeLinkDomain: String?
4243
var actionCodeRequestType: ActionCodeRequestType = .inApp
4344

4445
let spinner = UIActivityIndicatorView(style: .medium)
@@ -69,6 +70,7 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
6970
let settings = ActionCodeSettings()
7071
settings.url = actionCodeContinueURL
7172
settings.handleCodeInApp = (actionCodeRequestType == .inApp)
73+
settings.linkDomain = actionCodeLinkDomain
7274
return settings
7375
}
7476

@@ -156,6 +158,9 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
156158
case .continueURL:
157159
changeActionCodeContinueURL(at: indexPath)
158160

161+
case .linkDomain:
162+
changeActionCodeLinkDomain(at: indexPath)
163+
159164
case .requestVerifyEmail:
160165
requestVerifyEmail()
161166

@@ -552,7 +557,7 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
552557
private func changeActionCodeContinueURL(at indexPath: IndexPath) {
553558
showTextInputPrompt(with: "Continue URL:", completion: { newContinueURL in
554559
self.actionCodeContinueURL = URL(string: newContinueURL)
555-
print("Successfully set Continue URL to: \(newContinueURL)")
560+
print("Successfully set Continue URL to: \(newContinueURL)")
556561
self.dataSourceProvider.updateItem(
557562
at: indexPath,
558563
item: Item(
@@ -565,6 +570,22 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
565570
})
566571
}
567572

573+
private func changeActionCodeLinkDomain(at indexPath: IndexPath) {
574+
showTextInputPrompt(with: "Link Domain:", completion: { newLinkDomain in
575+
self.actionCodeLinkDomain = newLinkDomain
576+
print("Successfully set Link Domain to: \(newLinkDomain)")
577+
self.dataSourceProvider.updateItem(
578+
at: indexPath,
579+
item: Item(
580+
title: AuthMenu.linkDomain.name,
581+
detailTitle: self.actionCodeLinkDomain,
582+
isEditable: true
583+
)
584+
)
585+
self.tableView.reloadData()
586+
})
587+
}
588+
568589
private func requestVerifyEmail() {
569590
showSpinner()
570591
let completionHandler: ((any Error)?) -> Void = { [weak self] error in

FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/OtherAuthMethodControllers/PasswordlessViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class PasswordlessViewController: OtherAuthViewController {
3232
// MARK: - Firebase 🔥
3333

3434
private let authorizedDomain: String = "ENTER AUTHORIZED DOMAIN"
35+
private let customDomain: String = "ENTER AUTHORIZED HOSTING DOMAIN"
3536

3637
private func sendSignInLink(to email: String) {
3738
let actionCodeSettings = ActionCodeSettings()
@@ -42,6 +43,7 @@ class PasswordlessViewController: OtherAuthViewController {
4243
// The sign-in operation must be completed in the app.
4344
actionCodeSettings.handleCodeInApp = true
4445
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
46+
actionCodeSettings.linkDomain = customDomain
4547

4648
AppManager.shared.auth()
4749
.sendSignInLink(toEmail: email, actionCodeSettings: actionCodeSettings) { error in

0 commit comments

Comments
 (0)