AppManager.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. @testable import FirebaseAuth
  15. import FirebaseCore
  16. import UIKit
  17. /// Manage FirebaseApp instances for the Sample app
  18. class AppManager {
  19. static let shared = AppManager()
  20. private var defaultApp: FirebaseApp
  21. private var otherApp: FirebaseApp
  22. var app: FirebaseApp
  23. // Initialise Auth with TenantConfig
  24. let tenantConfig = Auth.TenantConfig(tenantId: "{{TENANT_ID}}", location: "{{LOCATION}}")
  25. func auth() -> Auth {
  26. return Auth.auth(app: app, tenantConfig: tenantConfig)
  27. }
  28. private init() {
  29. defaultApp = FirebaseApp.app()!
  30. app = FirebaseApp.app()!
  31. guard let path = Bundle.main.path(forResource: "GoogleService-Info_multi", ofType: "plist"),
  32. let options = FirebaseOptions(contentsOfFile: path) else {
  33. fatalError("GoogleService-Info_multi.plist must be added to the project")
  34. }
  35. FirebaseApp.configure(name: "OtherApp", options: options)
  36. guard let other = FirebaseApp.app(name: "OtherApp") else {
  37. fatalError("Failed to find OtherApp")
  38. }
  39. otherApp = other
  40. }
  41. func toggle() {
  42. if app == defaultApp {
  43. app = otherApp
  44. } else {
  45. app = defaultApp
  46. }
  47. }
  48. }